Combo Box dependent on Text Box

G

Guest

I have looked at the threads in search of a solution to my problem but most
of the ones I found were for cascading combo box. I am trying to populate a
combo box dependent on what value is in a bounded text box. I tried putting
the SQL on the row source of the combo box property and when that didn't work
I wrote VBA code for the On Load event of the form. Here is the code that I
wrote:
If Not IsNull(Me!ProductName.Value) Then
Dim MySQL As String
MySQL = "Select distinct MSP.[Product]"
MySQL = MySQL + " From [Master_SoftwareProduct] MSP "
MySQL = MySQL + " Where """ + Me!ProductName.Value + """ is not null"
MySQL = MySQL + " And MSP.[Product] like """ + Me!ProductName.Value + "%"""

Me!ProductComboBox.RowSourceType = "Table/Query"
Me!ProductComboBox.RowSource = MySQL
End If

I am not getting anything in the combo box. I ran the SQL independently and
it gave me results back. Any help is appreciated.
 
G

Guest

Thanks for the response. I tried the updated SQL and I am still not getting
anything. Should I put the code in another event besides the On Load event of
the form?

Ofer said:
try that
MySQL = "Select distinct MSP.[Product]"
MySQL = MySQL & " From [Master_SoftwareProduct] MSP "
MySQL = MySQL & " Where MSP.[Product] like ('" & Me!ProductName.Value & "*')"

LOP said:
I have looked at the threads in search of a solution to my problem but most
of the ones I found were for cascading combo box. I am trying to populate a
combo box dependent on what value is in a bounded text box. I tried putting
the SQL on the row source of the combo box property and when that didn't work
I wrote VBA code for the On Load event of the form. Here is the code that I
wrote:
If Not IsNull(Me!ProductName.Value) Then
Dim MySQL As String
MySQL = "Select distinct MSP.[Product]"
MySQL = MySQL + " From [Master_SoftwareProduct] MSP "
MySQL = MySQL + " Where """ + Me!ProductName.Value + """ is not null"
MySQL = MySQL + " And MSP.[Product] like """ + Me!ProductName.Value + "%"""

Me!ProductComboBox.RowSourceType = "Table/Query"
Me!ProductComboBox.RowSource = MySQL
End If

I am not getting anything in the combo box. I ran the SQL independently and
it gave me results back. Any help is appreciated.
 
G

Guest

If the value comming from Me!ProductName.Value entered only later, and not
when the form is loaded then put the code on the after update event of the
field

else check as followed:
1. first put a break in your code on the onload
2. use your debuger to see what string you get from MySQL copy it to a query
and see if you get any error message.
3. see if you get any value from Me!ProductName.Value




LOP said:
Thanks for the response. I tried the updated SQL and I am still not getting
anything. Should I put the code in another event besides the On Load event of
the form?

Ofer said:
try that
MySQL = "Select distinct MSP.[Product]"
MySQL = MySQL & " From [Master_SoftwareProduct] MSP "
MySQL = MySQL & " Where MSP.[Product] like ('" & Me!ProductName.Value & "*')"

LOP said:
I have looked at the threads in search of a solution to my problem but most
of the ones I found were for cascading combo box. I am trying to populate a
combo box dependent on what value is in a bounded text box. I tried putting
the SQL on the row source of the combo box property and when that didn't work
I wrote VBA code for the On Load event of the form. Here is the code that I
wrote:
If Not IsNull(Me!ProductName.Value) Then
Dim MySQL As String
MySQL = "Select distinct MSP.[Product]"
MySQL = MySQL + " From [Master_SoftwareProduct] MSP "
MySQL = MySQL + " Where """ + Me!ProductName.Value + """ is not null"
MySQL = MySQL + " And MSP.[Product] like """ + Me!ProductName.Value + "%"""

Me!ProductComboBox.RowSourceType = "Table/Query"
Me!ProductComboBox.RowSource = MySQL
End If

I am not getting anything in the combo box. I ran the SQL independently and
it gave me results back. Any help is appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top