Inserting not working

J

Johnny Bright

Hi there!

I seem to have a mental block for querying in code.

I'm trying to do the following:

Private Sub Command72_Click()
Dim mydb As DAO.Database
Set mydb = CurrentDb

mydb.Execute "Insert Into tblProjects (strProjectID, " _
& "strProjectName) values (" _
& strProjectID & ", " _
& strProjectName & " )"
End Sub

I get a Run Time error 3075

Syntax Error (missing operator) in query expression 'Database Test'

with 'Database Test' being the name of the project in my strProjectName field.

What am I doing wrong?
 
G

Graham Mandeno

Hi Johnny

Any textual data in a SQL statement needs to be exclosed in either single or
double quotes. Try this:

mydb.Execute "Insert Into tblProjects (strProjectID, " _
& "strProjectName) values (" _
& strProjectID & ", """ _
& strProjectName & """ )"
 

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