Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO stumper...

Status
Not open for further replies.

DeadHeat

MIS
Sep 10, 2008
2
US
Can someone please tell me what is wrong with my code below? If I use "User" as the table name my code does NOT work, but if I name it something else it works just fine!

strFirstName = InputBox("First name?")
strLastName = InputBox("Last name?")
strUserName = InputBox("Username?")
strPassword = InputBox("Password?")
strDept = InputBox("Dept?")
strProgram = InputBox("Program?")

strSourceFile = "C:\User.mdb"

Set objADO = CreateObject("ADODB.Connection")
objADO.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strSourceFile)
strSQL = "INSERT INTO User (User First Name], [User Last Name], [User Login Name], [User Password], [User Department], [User Program]) " & _
"VALUES ('"& strFirstName &"', '"& strLastName &"', '"& strUsername &"', '"& strPassword &"', '"& strDept &"', '"& strProgram &"');"
objADO.Execute(strSQL)
objADO.Close
 
>"INSERT INTO User (User First Name],
[tt]"INSERT INTO User ([red][[/red]User First Name], [/tt]
 
Unfortunately even after I corrected this, it still does not work! Please help.
 
You have to put [User] in brackets as well:

Code:
Insert Into [User] ([User First Name],...

As mentioned, 'User' is a reserved word for Access SQL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top