Incomple Query Clause

S

sherriross81

Hello,

I am trying to retreive a value from my database depending on which value
the user selects in a combo box. Here is my code:

Dim strSQL As String

strSQL = "Select ID FROM 'Computer Inventory' " _
& "WHERE 'PC Name' = " & Me.cboComputerName & ""
CurrentDb.Execute strSQL, dbFailOnError

Me.Requery

I keep getting an incomplete query clause error. I can't seem to figure out
what is missing.

Thanks in advance.
 
M

mscertified

Try:

strSQL = "Select ID FROM [Computer Inventory] " _
& "WHERE [PC Name] = '" & Me.cboComputerName & "'"
CurrentDb.Execute strSQL, dbFailOnError

Note the [] around the table and column names (it's best NOT to use embedded
blanks in names!) and you need a single quote after the =

-Dorian
 
S

sherriross81

Thank you for the advice on column names.

I tried updating the code as you directed and I get an error that says
Cannot Execute Select Statement Run time error 3065.
 
S

sherriross81

Nevermind I just realized I can't used currentdb.execute with a select
statement.

Thanks for helping with the code.

mscertified said:
Try:

strSQL = "Select ID FROM [Computer Inventory] " _
& "WHERE [PC Name] = '" & Me.cboComputerName & "'"
CurrentDb.Execute strSQL, dbFailOnError

Note the [] around the table and column names (it's best NOT to use embedded
blanks in names!) and you need a single quote after the =

-Dorian

sherriross81 said:
Hello,

I am trying to retreive a value from my database depending on which value
the user selects in a combo box. Here is my code:

Dim strSQL As String

strSQL = "Select ID FROM 'Computer Inventory' " _
& "WHERE 'PC Name' = " & Me.cboComputerName & ""
CurrentDb.Execute strSQL, dbFailOnError

Me.Requery

I keep getting an incomplete query clause error. I can't seem to figure out
what is missing.

Thanks in advance.
 
M

mscertified

you need CurrentProject.Connection.Execute strSQL

-Dorian

sherriross81 said:
Nevermind I just realized I can't used currentdb.execute with a select
statement.

Thanks for helping with the code.

mscertified said:
Try:

strSQL = "Select ID FROM [Computer Inventory] " _
& "WHERE [PC Name] = '" & Me.cboComputerName & "'"
CurrentDb.Execute strSQL, dbFailOnError

Note the [] around the table and column names (it's best NOT to use embedded
blanks in names!) and you need a single quote after the =

-Dorian

sherriross81 said:
Hello,

I am trying to retreive a value from my database depending on which value
the user selects in a combo box. Here is my code:

Dim strSQL As String

strSQL = "Select ID FROM 'Computer Inventory' " _
& "WHERE 'PC Name' = " & Me.cboComputerName & ""
CurrentDb.Execute strSQL, dbFailOnError

Me.Requery

I keep getting an incomplete query clause error. I can't seem to figure out
what is missing.

Thanks in advance.
 

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