Combobox and conditional VBA scripts

anissw

Registered User.
Local time
Today, 00:04
Joined
Jun 11, 2012
Messages
55
Hi- I have a database that has multiple buttons for generating 1 report, but different restrictions. I am taking this database and removing the buttons to implement combo boxes I have 2 combo boxes currently setup and want to implement VBA script with conditional statements depending on the values in the combo boxes. I haven't coded VBA in some time and need some help. First the values in the first combo box is pulling the ID instead of the text value and I can't figure out why. Second my VBA script when I click the execute button doesn't run, nor displays an error. The currently run by queries to import data into INVENTORY table and have it display. If you can review my database and VBA code and give insight into what I am overlooking, that would be helpful.

Thanks-

Anissw
 

Attachments

I dont have access 2007 here, but from what you said to get the text from the combobox try using comboboxname.coloumn(0) or comboboxname.coloumn(1) etc... depending on which column has the text.

The execute button (is there a onclick procedure?)

Finally they are not VBA "scripts" they are modules and procedures.
 
Hello anissw, welcome to AWF.. :)

First the values in the first combo box is pulling the ID instead of the text value and I can't figure out why.
This is because in the unbound ComboBox (cmbReport) you have Column Count = 1, Change it to 2 and the Column Width to 0 cm; 3.704 cm
Second my VBA script when I click the execute button doesn't run, nor displays an error.
Well your ComboBoxes are bound to Column 1, but what it is looking for in the VBA Code is the second column, so what you need is to change your code to..
Code:
If Me.cmbReport.Column(1) = "Inventory" And Me.Type.Column(1) = "Gateway" Then
Instead of
Code:
If Me.cmbReport.Value = "Inventory" And Me.Type.Value = "Gateway" Then
As the values returned by the ComboBoxes are Report ID's.. When I execute with the changes code it runs fine.. When I say fine the If gets executed, since it is a stripped down version it cannot find the Query you are looking for.. So hope that helps you..
 
Thank you so much for replying back. I am including a screenshot of when I choose the 1st combobox, it displays the ID field instead of the ReportName field. When I change the column count, it then displays the ID field and ReportName field. I am interested in having the ReportName field to be displayed so that when I execute, my conditional statements will be referencing the values in combo box 1 and combo box 2. I feel I am overlooking something simple. :banghead:

Thanks you-

Anissw
 

Attachments

Hello anissw, you might have missed something I had mentioned..
This is because in the unbound ComboBox (cmbReport) you have Column Count = 1, Change it to 2 and the Column Width to 0 cm; 3.704 cm
 
Thanks so much!! As you indicated, I made the changes and it did work.:D
 

Users who are viewing this thread

Back
Top Bottom