2 criteria "then" statement pulling from Access

I am hving problem with below code:

If cboequipnum.Text = "Equipment 1" And cbomeslotnum.text = "A1" Then
Data1.RecordSource = "select * from main table where Meslot = 'A1' And Equipment# = 'Equipment1' "

main table is table in access db, and meslot and equipment# are fields of main table

I think I have the "select * "syntax wrong, as I get an some sort of date error when I try to excecute this code...If I remove the last line of the above code it will work.  Adding the and statement seems to throw it off.

Any suggestions
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

put [main table]
If "main table" is the table name with a space in it, change your query to [main table], such as:

select *
from [main table]
where Meslot = 'A1'
      And Equipment# = 'Equipment1'

I just reformatted it for readability, but it is the same thing.  If you are still having problems, but brackets [] around the field names as well.  If that doesn't work then also use double quotes, such as:

"select * " + _
"from [main table] " + _
"where [Meslot] = ""A1""" + _
     " And [Equipment#] = ""Equipment1"""

Good luck.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Data1.RecordSource = "select * from [main table] where Meslot = 'A1' And Equipment# = 'Equipment1' " 

also I hope that Equipment# and Meslot are the text fields...

If you want to be a little more elegant, you might also try the following:

Dim strSql As String

If cboequipnum.Text = "Equipment 1" And cbomeslotnum.Text = "A1" Then
  strSql = "select * " + _
           "from [main table] " + _
           "where [Meslot] = """ + cbomeslotnum.Text + """" + _
           "  And [Equipment#] = """ + cboequipnum.Text
End If

Data1.RecordSource = strSql

Good Luck.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.