You won't be able to turn people's personal beliefs about racism through legislation, but you can help with companies and professional settings. By telling companies they can't refuse service due to race or you can't fire people due to race, it does help to curb racism in the professional environment.
To some degree, racism can be controlled by passing legislation such as "hate crimes" laws. These felonious acts come with a harsher penalty than a crime not involving racist motivations. Although the law cannot change people's thoughts, they can prevent people from acting upon their beliefs. In addition, when hate crimes are reported to the public, this acts as additional deterrent for people not to commit crimes of racism. Racism may never be eradicated but the crimes that result can be controlled.
One of the great things about the United States is that we have a right to say whatever we want, no matter whether it's loving or hating. If someone wants to be racist, it may not be morally right, but it certainly is their right under the Constitution. Anything restricting this by legislation would be infringing on the First Amendment.
The government has no right to control the opinions of individuals, and it has no right to limit freedom of association. Companies can be as bigoted as they want in hiring. People have intrinsic rights, the government, no matter how noble in cause, can change those rights unless the person being limited has limited the Bill of Rights Freedoms of others.
Education is the only way to get rid of racism. Passing on traits from parents to children keeps racism alive. Experiences and circumstances can also breed fear and hatred of those people who are different. Racism cannot be controlled by laws alone. Laws can help make things equal, but they cannot erase inherent fears that exist in the collective consciousness.
Whether we like it or not, it is human nature for people to generally prefer people who are similar to themselves; this naturally includes race. As a result, there has always been racism in human society, and there always will be. We can use legislation to minimize discrimination in society, but any attempt to legislate away racism would be draconian and ultimately fruitless.
No, racism cannot be controlled by legislation. You cannot legislate away feelings, emotions, and hatreds. Laws can be made to make sure “Equal Opportunity” exists and is being followed. Laws can be made that make it illegal to target someone based on their race. But regardless, there is no legislation that can force people to let go of negative emotions and old hatreds.