Hi folks,
I'm a complete newbie with Access, but I have a great deal of experience in using VBA with Excel. However, I've realised that one of my Excel toys needs to be converted to Access owing to the volume of data it holds.
As such, yesterday I started to "play" with Access and built a couple of tables, queries and forms. On one of the forms I have a ComboBox (called startDate), I've added an after update event to this to trigger a macro to search for a record in a table called shiftTable, and return 3 pieces of data when it locates the record.
I built the query to do this using the Access query design which works correctly, and then grabbed the SQL to use in the macro, this is shown below.
This is the macro that I've built around that SQL....
However, every time I run it I get a 3075 missing operator error (in this example I selected 27/01/2011 in the startDate ComboBox);
I've tried various things to fix it, including converting the date to US format, putting a space in front of the FROM command, declaring stDate as string instead of date. I'm getting frustrated now, especially as I suspect I'm missing something very obvious. All help appreciated!
EDIT:
As an experiment, I just chucked a msgBox in before the DoCmd statement to show me the value of ssqlCom, which returns this:
Thanks,
James.
I'm a complete newbie with Access, but I have a great deal of experience in using VBA with Excel. However, I've realised that one of my Excel toys needs to be converted to Access owing to the volume of data it holds.
As such, yesterday I started to "play" with Access and built a couple of tables, queries and forms. On one of the forms I have a ComboBox (called startDate), I've added an after update event to this to trigger a macro to search for a record in a table called shiftTable, and return 3 pieces of data when it locates the record.
I built the query to do this using the Access query design which works correctly, and then grabbed the SQL to use in the macro, this is shown below.
Code:
SELECT shiftTable.amWatch, shiftTable.pmWatch, shiftTable.nsWatch
FROM shiftTable
WHERE (((shiftTable.activityDate)=activitydetail.startDate));
This is the macro that I've built around that SQL....
Code:
Private Sub startDate_AfterUpdate()
Dim ssqlCom As String
Dim stDate As Date
Me.End_Date = Me.startDate
stDate = Me.startDate
ssqlCom = "SELECT shiftTable.amWatch, shiftTable.pmWatch, shiftTable.nsWatch" & _
"FROM shiftTable " & _
"WHERE shiftTable.activityDate=#" & stDate & "#;"
DoCmd.RunSQL (ssqlCom)
End Sub
However, every time I run it I get a 3075 missing operator error (in this example I selected 27/01/2011 in the startDate ComboBox);
Syntax error(missing operator) in query expression
'shiftTable.nsWatchFROM shiftTable WHERE
shiftTable.activityDate=#27/01/2011#'.
I've tried various things to fix it, including converting the date to US format, putting a space in front of the FROM command, declaring stDate as string instead of date. I'm getting frustrated now, especially as I suspect I'm missing something very obvious. All help appreciated!
EDIT:
As an experiment, I just chucked a msgBox in before the DoCmd statement to show me the value of ssqlCom, which returns this:
SELECT shiftTable.amWatch, shiftTable.pmWatch, shiftTable.nsWatchFROM shiftTable WHERE shiftTable.activityDate=#27/01/2011#;
Thanks,
James.
Last edited: