I am using Microsoft Access to update a table on a SQL Server. The table on the SQL Server has an autogenerated number in it so I cannot just update the table and be done with it. I have written some code (will follow) to generate a number in the table and also to update the table. The problem I am having is that for my insert statement I get the following error:
Run-time error '3346': Number of query values and destination fields not the same.
Here is my insert statement nested into a do while loop:
Do While Not rst.EOF
UserRec = "Insert INTO [UsersTemp] ([UserID], [Location], [FullName], [Dept]) Values ('" & NxtUserID & " , " & Location & ", " & E - Mail & ", " & Department & "')"
myDB.Execute UserRec
NxtUserID = NxtUserID + 1
Loop
The table it is going into (UserRec) has the following design:
UserID - number
Location - text
FullName - text
Dept - text
The values going into UserRec table are from different tables, but I create a query to pull them together as follows:
sqlStr = "SELECT [Lafayette Inventory].[Location], [Lafayette Inventory].[Department], [Lafayette Inventory].[E-Mail] FROM [Lafayette Inventory] LEFT JOIN Users ON [Lafayette Inventory].[E-Mail]=[Users].[FULLNAME] WHERE ((([Users].[FULLNAME]) Is Null));"
[Lafayette Inventory].[Location] - text
[Lafayette Inventory].[Department] - text
[Lafayette Inventory].[E-Mail] - text
The code to generate the UserID is also a query and is as follows:
sqlStr2 = "SELECT dbo_LASTUSER.LASTUSER FROM dbo_TIUSER INNER JOIN dbo_LASTUSER ON dbo_TIUSER.USERID = dbo_LASTUSER.LASTUSER;"
This information is pulled from a table on the SQL Server which has the following design:
LastUser - Number
I cannot figure out why I am getting that error. From what I see, the query values and the destination fields are the same. Any help will be greatly appreciated.
Thanks!
Run-time error '3346': Number of query values and destination fields not the same.
Here is my insert statement nested into a do while loop:
Do While Not rst.EOF
UserRec = "Insert INTO [UsersTemp] ([UserID], [Location], [FullName], [Dept]) Values ('" & NxtUserID & " , " & Location & ", " & E - Mail & ", " & Department & "')"
myDB.Execute UserRec
NxtUserID = NxtUserID + 1
Loop
The table it is going into (UserRec) has the following design:
UserID - number
Location - text
FullName - text
Dept - text
The values going into UserRec table are from different tables, but I create a query to pull them together as follows:
sqlStr = "SELECT [Lafayette Inventory].[Location], [Lafayette Inventory].[Department], [Lafayette Inventory].[E-Mail] FROM [Lafayette Inventory] LEFT JOIN Users ON [Lafayette Inventory].[E-Mail]=[Users].[FULLNAME] WHERE ((([Users].[FULLNAME]) Is Null));"
[Lafayette Inventory].[Location] - text
[Lafayette Inventory].[Department] - text
[Lafayette Inventory].[E-Mail] - text
The code to generate the UserID is also a query and is as follows:
sqlStr2 = "SELECT dbo_LASTUSER.LASTUSER FROM dbo_TIUSER INNER JOIN dbo_LASTUSER ON dbo_TIUSER.USERID = dbo_LASTUSER.LASTUSER;"
This information is pulled from a table on the SQL Server which has the following design:
LastUser - Number
I cannot figure out why I am getting that error. From what I see, the query values and the destination fields are the same. Any help will be greatly appreciated.
Thanks!