WithEvents Access.ComboBox (1 Viewer)

Mario R. Perez

New member
Local time
Today, 03:12
Joined
May 14, 2020
Messages
12
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:12
Joined
Feb 19, 2002
Messages
43,275
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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:12
Joined
Sep 21, 2011
Messages
14,299
I would say you need at least a space either side of your OR?
If you followed Pat's advice, that would be obvious.
 

jdraw

Super Moderator
Staff member
Local time
Today, 03:12
Joined
Jan 23, 2006
Messages
15,379
Mario,
Can you post your database with some instructions along with a description of what you want to accomplish?
 

Edgar_

Active member
Local time
Today, 02:12
Joined
Jul 8, 2023
Messages
430
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

Top Bottom