I'm currently having a problem with the DoCmd.RunSQL command in VBA. I've written a function that has a number of parameters and then runs a piece of SQL selecting records from a table using a Where clause where each record found should have field values that match the corresponding parameters passed to the function. Unfortunately I can't get it to do that and it either has a syntax error or runs and requests the parameters from the user.
Example Code:
Public Function Find_Query(CCode, CName As TextBox, _
Csource As ComboBox)
DoCmd.RunSQL "SELECT [Course Code], [Course Title]," & _
"[Course Source] INTO [tblTempFind]" & _
FROM [tblCourses]" & _
"WHERE ((([Course Code])=CCode) AND" & _
"(([Course Title])=CName) AND" & _
"(([Course Source])=CSource));"
End Function
Example Code:
Public Function Find_Query(CCode, CName As TextBox, _
Csource As ComboBox)
DoCmd.RunSQL "SELECT [Course Code], [Course Title]," & _
"[Course Source] INTO [tblTempFind]" & _
FROM [tblCourses]" & _
"WHERE ((([Course Code])=CCode) AND" & _
"(([Course Title])=CName) AND" & _
"(([Course Source])=CSource));"
End Function