Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code help?

Status
Not open for further replies.

skate

Technical User
Nov 29, 2002
65
CA
There is something wrong with my code. I think it has to do with the value of my combobox being numeric. Any suggestions?

Private Sub Name_Combo_Change()
Dim txtSearchString As Variant
Dim strSQL As String
txtSearchString = Me.Name_Combo.Value
strSQL = "SELECT Month.SIndex, Month.MIndex, Month.MOrder, Month.Month, Month.[Job Hrs], Month.[Eng Hrs], Month.[Stat Hrs],Month.[Bank Hrs],Month.[Total Hrs] FROM [Month Entry] INNER JOIN [Month] ON [Month Entry].MOrder = Month.Month WHERE (((Month.SIndex) Like '1*')) ORDER BY Month.MOrder"
strSQL = strSQL & "WHERE (([Month].[SIndex]) Like '" & txtSearchString & "*') "
strSQL = strSQL & "ORDER BY [Month].[MOrder]"
Me!lstResults.RowSource = strSQL
Me!lstResults.Requery
Me!Name_Combo.SetFocus
End Sub
 
Try this in the Like string.

Like """ & txtSearchString & "*""


Paul
 
The best way to debug sql with variables is to debug print the sequal statement with the variables assigned. Copy the immediate window and paste the text into you query designer. Try to run the query from there and you should be able to see the problem.
 
Always make sure you add either a leading or trailing space to your statements so nothing abutts when you concatenate it (eg FROM tblTableWHERE, etc). Also, you can create your SQL in QBE and then select the show SQL option to use for cut and paste.

Good Luck!
 
Your SQL statement is screwed up.
You have 2 Where clauses and 2 Order By's
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top