WithEvents Access.ComboBox

Mario R. Perez

New member
Local time
Today, 09:29
Joined
May 14, 2020
Messages
16
Good Morning Everyone.

I have this class.

Private WithEvents m_cbo As Access.ComboBox
Private Const OrigenClient As String = "SELECT TblCustomer.id, TblCustomer.FldfullName,tblcustomer.[FldPhone] From TblCustomer where TblCustomer.FldfullName "
'Private Const Fono As String = "FldPhone"

Public Sub load(cbO As Access.ComboBox)
Set m_cbo = cbO
m_cbo.RowSource = OrigenClient
m_cbo.OnGotFocus = "[Event Procedure]"
m_cbo.OnKeyUp = "[Event Procedure]"
End Sub

Private Sub m_cbo__GotFocus()
m_cbo.Dropdown
End Sub



Private Sub m_cbo_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Exit Sub
End If
If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
Else
m_cbo.RowSource = OrigenClient & " LIKE '*" & m_cbo.text & "*'" & "OR" & "(" & m_cbo.Column(2) & " Like '" & "*" & m_cbo.text & "*" & "'));"

m_cbo.Dropdown
End If

End Sub

Before of "
& "OR" & "(" & m_cbo.Column(2) & " Like '" & "*" & m_cbo.text & "*" & "'));"" works perfect but when i want to use it with the "OR.." it fails. you know where the problem is.
Thanks for advance.
 
This is an inappropriate use of a class but that's neither here nor there. The point of creating a class is to create generic code that will be used, unchanged, in other situations. This is not generic code and so should just be placed in the appropriate form event procedure.

When debugging a query that is built using vba, stop the code on the line that builds the sql string and print the string to the debug window. If you don't see the syntax error, copy the string and paste it into the QBE and see what it has to say. You will frequently get a better error message.

PS when you paste code PLEASE use the proper tool for code so that the formatting is retained.
 
I would say you need at least a space either side of your OR?
If you followed Pat's advice, that would be obvious.
 
Mario,
Can you post your database with some instructions along with a description of what you want to accomplish?
 
Those emojis don't let me see the code, I hope it's a dot and not an underscore , as suggested by the tooltip.
m_cbo.OnGotFocus
m_cbo_OnGotFocus
Public Sub load(cbO As Access.ComboBox)
Set m_cbo = cbO
m_cbo.RowSource = OrigenClient
m_cbo_OnGotFocus = "[Event Procedure]"
m_cbo_OnKeyUp = "[Event Procedure]"
End Sub

Also, that OR needs some space there.
Rich (BB code):
m_cbo.RowSource = OrigenClient & " LIKE '*" & m_cbo.text & "*'" & "OR" & "(" & m_cbo.Column(2) & " Like '" & "*" & m_cbo.text & "*" & "'));"

Try to add the spaces
Rich (BB code):
m_cbo.RowSource = OrigenClient & " LIKE '*" & m_cbo.text & "*'" & " OR " & "(" & m_cbo.Column(2) & " Like '" & "*" & m_cbo.text & "*" & "'));"

See if that helps.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom