Incomple Query Clause

  • Thread starter Thread starter sherriross81
  • Start date Start date
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.
 
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
 
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.
 
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.
 
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.
 
Back
Top