SQL statement not working

  • Thread starter RedHeadedMonster via AccessMonster.com
  • Start date
R

RedHeadedMonster via AccessMonster.com

I have a login form that will login who is using the database and the date.
It has the following code connected to the onClick event of an OK button:

Dim rosterSQL As String

Set rosterSQL = "Insert into tblLOGIN([rosterID], [loginDate]) Values ('" &
Me.rosterID & "', Now() );"
DoCmd.SetWarnings (0)
DoCmd.RunSQL rosterSQL

please note the tick marks vs. quotes around rosterID: ' " & Me.RosterID &
" '

The form has rosterID as a field. But when I run the code I get a "Compile
error Object required" and the following is highlighted in the code: .
RosterID

Any idea what my hickup is?
Thanx!
RHM
 
M

Mike Painter

RedHeadedMonster said:
I have a login form that will login who is using the database and the
date. It has the following code connected to the onClick event of an
OK button:

Dim rosterSQL As String

Set rosterSQL = "Insert into tblLOGIN([rosterID], [loginDate]) Values
('" & Me.rosterID & "', Now() );"
DoCmd.SetWarnings (0)
DoCmd.RunSQL rosterSQL

run msgbox rosterSQL
I suspect you will see ' & Me.rosterID &

"Insert into tblLOGIN([rosterID], [loginDate]) Values '" & Me.rosterID &
"', Now() );"
 
M

Maurice

Have you tried switching the single apostrophes in front of the double quotes
like:

"' & Me.RosterID & '"

But then again if your id is a numeric value you should try it without the
quotes and double quotes by just placing me.rosterid.

i'd say give it a try..
 
R

RedHeadedMonster via AccessMonster.com

Im afraid Im not understanding what you are saying.

Mike said:
I have a login form that will login who is using the database and the
date. It has the following code connected to the onClick event of an
[quoted text clipped - 6 lines]
DoCmd.SetWarnings (0)
DoCmd.RunSQL rosterSQL

run msgbox rosterSQL
I suspect you will see ' & Me.rosterID &

"Insert into tblLOGIN([rosterID], [loginDate]) Values '" & Me.rosterID &
"', Now() );"
 
R

RedHeadedMonster via AccessMonster.com

When I do this I get the same error...except this time is highlights
rosterSQL
Have you tried switching the single apostrophes in front of the double quotes
like:

"' & Me.RosterID & '"

But then again if your id is a numeric value you should try it without the
quotes and double quotes by just placing me.rosterid.

i'd say give it a try..
I have a login form that will login who is using the database and the date.
It has the following code connected to the onClick event of an OK button:
[quoted text clipped - 16 lines]
Thanx!
RHM
 
M

Mike Painter

RedHeadedMonster said:
Im afraid Im not understanding what you are saying.

Mike said:
I have a login form that will login who is using the database and
the date. It has the following code connected to the onClick event
of an
[quoted text clipped - 6 lines]
DoCmd.SetWarnings (0)
DoCmd.RunSQL rosterSQL

run msgbox rosterSQL
I suspect you will see ' & Me.rosterID &

"Insert into tblLOGIN([rosterID], [loginDate]) Values '" &
Me.rosterID & "', Now() );"

If I have problems with a SQL statement I put a message box in place of the
actual execution phrase.
Then I can look at it. If instead of
DoCmd.RunSQL rosterSQL
you place
msgbox rosterSQL

You will see your problem.
The last line is a corrected version of what you posted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top