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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert not working

Status
Not open for further replies.

rjoshi2

Programmer
Sep 10, 2002
110
US
Why is the insert (inseertID) not working? It always inserts 0 even when IDnumber equal 2 or another number. Any help would be appreciated.

Thank You,
rjoshi2

Option Compare Database
Option Explicit
Dim IDNumber As Integer

Private Sub Document__AfterUpdate()
Dim insertID As String
MsgBox ("User ID: " & IDNumber)
insertID = "INSERT INTO FY03COMREG( [User ID] ) " & _
"SELECT '" & IDNumber & "' ;"
MsgBox ("User ID: " & IDNumber)
CurrentDb.Execute insertID
End Sub

Private Sub Form_Load()
MsgBox ("Hello: " & CurrentUser & "!")
Dim getuserID As String

'use dlookup not select
IDNumber = DLookup("[User ID]", "Users", "[User Name] = '" & CurrentUser & "'")
MsgBox ("User ID: " & IDNumber)
End Sub
 
You have dimensioned IDNumber as an Integer, therefore the single quotes are not needed in the select statement:

You have:
insertID = "INSERT INTO FY03COMREG( [User ID] ) " & _
"SELECT '" & IDNumber & "' ;"

Should be:
insertID = "INSERT INTO FY03COMREG( [User ID] ) " & _
"SELECT " & IDNumber & " ;"

Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
I have change my code again buecause I got rid of the users table but it is still not working. Any help would be appreciated.

Thank You,
rjoshi2

In this section of code I am getting an error at line:
"'" & FY03COMREG.[User ID] & " = '" & CurrentUser & "'"
It says variable not defined (referring to FY03COMREG). How do I define that table?

Option Compare Database
Option Explicit

Private Sub Form_Load()
Dim getdata As String

MsgBox ("Hello: " & CurrentUser & "!")

getdata = "Select * from FY03COMREG where" & _
"'" & FY03COMREG.[User ID] & " = '" & CurrentUser & "'"

Me.RecordSource = getdata
Me.Requery

End Sub

In this next section I am getting a run time error (3061) "Too few parameters. Expect 1' at line:
CurrentDb.Execute insertID

Private Sub OCB_AfterUpdate()
Dim insertID As String

MsgBox ("User ID: " & CurrentUser)
insertID = "INSERT INTO FY03COMREG( [User ID] ) " & _
"VALUES(" & CurrentUser & ") ;"
MsgBox ("User ID: " & CurrentUser)
CurrentDb.Execute insertID

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top