I am working with a form that contains two text boxes and a combo box. I want the combo box to only show you the options that are available to you after you enter two seperate values in the previous text boxes. I have the combo box showing three columns - two are the text box values and the other is a value that was not included in the text boxes. Once I select the one I want, I need to be able to print a report for the values I selected.
21 4067 NeoPa 32,556
Expert Mod 16PB
Perhaps if you post what is in the various fields we can understand what it is you want!?!?
I have a text box with Year
I have a text box with Make
I have a combo box with Model / Make / Year
I want the combo box to only show the vehicles with the year and make that were selected in the text boxes. I will also need to print a report showing the record that was selected.
NeoPa 32,556
Expert Mod 16PB
That's much more helpful.
Can you also explain how the data behind it is stored.
Is it a form linked to a single table (or updatable recordset) with records which all have all of those fields?
Or maybe the two TextBoxes must be made up from the data within the whole recordset?
This would be very helpful to understand what you need.
That's much more helpful.
Can you also explain how the data behind it is stored.
Is it a form linked to a single table (or updatable recordset) with records which all have all of those fields?
Or maybe the two TextBoxes must be made up from the data within the whole recordset?
This would be very helpful to understand what you need.
The data related to those text and combo boxes are all stored in one table - tblVehicle. The combo box gets the details from the tblVehicle, and lists them in the combobox.
NeoPa 32,556
Expert Mod 16PB
Assuming the textboxes are called txtYear & txtMake and that the combo is cmbModel.
The tblVehical fields are Year, Make & Model.
Lastly, that all fields are strings (text). - cmbModel.RecordSource = "SELECT [Model] " & _
-
"FROM [tblVehicle] " & _
-
"WHERE (([Year] = '" & txtYear & "') " & _
-
" AND ([Make] = '" & txtMake & "')) " & _
-
"ORDER BY [Model]"
Another alternative is to use Combos for all fields where the the selection list is extracted from the same table so :- - cmbYear.RecordSource = "SELECT DISTINCT [Year] " & _
-
"FROM [tblVehicle] " & _
-
"ORDER BY [Year]"
and - cmbMake.RecordSource = "SELECT DISTINCT [Make] " & _
-
"FROM [tblVehicle] " & _
-
"ORDER BY [Make]"
Obviously the txtYear & txtMake in the cmbModel.RecordSource code would have to change to cmbYear & cmbMake respectively.
Assuming the textboxes are called txtYear & txtMake and that the combo is cmbModel.
The tblVehical fields are Year, Make & Model.
Lastly, that all fields are strings (text). - cmbModel.RecordSource = "SELECT [Model] " & _
-
"FROM [tblVehicle] " & _
-
"WHERE (([Year] = '" & txtYear & "') " & _
-
" AND ([Make] = '" & txtMake & "')) " & _
-
"ORDER BY [Model]"
Another alternative is to use Combos for all fields where the the selection list is extracted from the same table so :- - cmbYear.RecordSource = "SELECT DISTINCT [Year] " & _
-
"FROM [tblVehicle] " & _
-
"ORDER BY [Year]"
and - cmbMake.RecordSource = "SELECT DISTINCT [Make] " & _
-
"FROM [tblVehicle] " & _
-
"ORDER BY [Make]"
Obviously the txtYear & txtMake in the cmbModel.RecordSource code would have to change to cmbYear & cmbMake respectively.
Where do I find the recordsource? I know ther is rowsorce whrn looking at the properties of the combobox but I do not see a recordsouce. Is this what I enter in VB? I am new to this and don't fully understand what needs to be done. I need to use the first example you gave me but I am not following it completely. Thanks again for all the help.
NeoPa 32,556
Expert Mod 16PB
You're absolutely right. I'm sorry.
You need to assign it to the 'RowSource' property whenever the value(s) in txtMake or txtYear change.
Put this in the AfterUpdate events of both objects.
So if i understand this correctly, I need to put the follwoing text in the after update section of the two txt boxes? Do I need anything in the Model combo box?
cmbModel.RecordSource = "SELECT [Model] " & _
"FROM [tblVehicle] " & _
"WHERE (([Year] = '" & txtYear & "') " & _
" AND ([Make] = '" & txtMake & "')) " & _
"ORDER BY [Model]"
NeoPa 32,556
Expert Mod 16PB
Nothing related to this question.
you might try something like this on the AfterUpdate event for the text boxes:-
me.cmbMake.filter = "Year = " & txtYear & " AND Make = " & txtMake
me.cmbMake.requery
HTH
Steve
Nothing related to this question.
I am getting a compile error when I enter the lines you have. Where in these lines are there single or double quotes? Would this nake a difference? What else could I be doing wrong?
you might try something like this on the AfterUpdate event for the text boxes:-
me.cmbMake.filter = "Year = " & txtYear & " AND Make = " & txtMake
me.cmbMake.requery
HTH
Steve
Thanks for the help as well steve but this one is not working for me either.
i get a compile error:
Method or data member not found.
And it brings up my txtYear.
Any more suggestions?
mebbe try:-
me.cmbMake.filteron = true
me.cmbMake.filter = "Year = '" & txtYear & "' AND Make = '" & txtMake & "'"
me.cmbMake.requery
Addition of single quotes around text variables in SQL code!!!
Steve
mebbe try:-
me.cmbMake.filteron = true
me.cmbMake.filter = "Year = '" & txtYear & "' AND Make = '" & txtMake & "'"
me.cmbMake.requery
Addition of single quotes around text variables in SQL code!!!
Steve
I still get the same error. I don't know what I am doing wrong!
I still get the same error. I don't know what I am doing wrong!
Sorry, got the wrong combo name! Try:-
me.cmbModel.filteron = true
me.cmbModel.filter = "Year = '" & txtYear & "' AND Make = '" & txtMake & "'"
me.cmbModel.requery Also- If txtYear and txtMake have a data source, you should use the data source name in your code
- Try using "Me." to prefix your field names
Steve
NeoPa 32,556
Expert Mod 16PB
you might try something like this on the AfterUpdate event for the text boxes:-
me.cmbMake.filter = "Year = " & txtYear & " AND Make = " & txtMake
me.cmbMake.requery
HTH
Steve
It's true you could put the WHERE part in the Filter instead (would be better in fact), and also the requery is good.
Beware this code though, It should be on the cmbModel object and the strings should be enclosed in quotes.
In short, take the ideas - don't copy/paste the code.
PS I should have refreshed again - I missed the conversation in between.
NeoPa 32,556
Expert Mod 16PB
I am getting a compile error when I enter the lines you have. Where in these lines are there single or double quotes? Would this make a difference? What else could I be doing wrong?
Ducky,
Copy and paste the text into a text editor to find where the quotes are. That's not something you should be asking someone to tell you. But in general, the double-quotes are around text in the program that must be treated as literal string values. The single-quotes are where, in the eventual data, a string needs to be passed to the SQL parser - in other words, in the SQL code.
The quotes will certainly make a difference - unlike prefixing the object names with Me. which is entirely superfluous in this situation.
I can help you with the code, but I need you to tell me where the compiler complains in your code.
This definitely works!!!
I just built a dummy form, with a simple data table ("Models": contains fields Make/Year/Model)
Use this code in the appropriate events:- - OnEnter event for cmbModel:
Private Sub cmbModel_Enter()
Me.cmbModel.RowSource = "SELECT Ident, Make, Year, Model FROM Models where year='" & Me.txtYear & "' and make='" & Me.txtMake & "'"
Me.cmbModel.Requery
End Sub
- OnLoad event of Form:
Private Sub Form_Load()
Me.cmbModel.RowSource = "SELECT Ident, Make, Year, Model FROM Models where year='" & Me.txtYear & "' and make='" & Me.txtMake & "'"
End Sub
You may not need to use the form's OnLoad event
Steve
PS
combo boxes don't have a filter property!!! (Doh!)
Steve
NeoPa 32,556
Expert Mod 16PB
That's good work CyberDwarf, but don't forget why the code was originally to be put in the AfterUpdate events of the two text boxes - we don't want a requery every time the user enters the Model field. That ensures the query is only rerun whan a change is made to what the query depends on.
Anyway, have fun and the solution is there for you Ducky.
we don't want a requery every time the user enters the Model field. That ensures the query is only rerun whan a change is made to what the query depends on.
Then you need to add the code to to the AfterUpdate events for both txtMake and txtYear - that's two lots of requerying??
Steve
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Daniel Hill |
last post by:
OK, I have very, VERY basic background knowledge of VB6
and have now upgraded to VB.NET and now I'm struggling to
bring up the forms I want.
What I am looking to do is to have a click a command...
|
by: CZERNAI |
last post by:
Hi
Am new to programming and to this process of asking questions. I believe I
have read all the threads concerning combo box questions but haven't found an
answer to my problem.
I am using ...
|
by: mumbaimacro |
last post by:
hi
i have two combo boxes in a form with values from a table.
i need a report to be opened by a button from the form ,The Report should show the values selected in the combo boxes in the form...
|
by: salad |
last post by:
I was wondering how you handle active/inactive elements in a combo box.
Let's say you have a combo box to select an employee. Joe Blow has
been selected for many record however Joe has left the...
|
by: =?Utf-8?B?amVmZmVyeQ==?= |
last post by:
i need help with a combo box and this same code works on my first tab with a
combo box. The error or problem i have is this code causes an index out of
range error when i run it on my second combo...
|
by: zufie |
last post by:
I have 4 combo boxes on a report for the fields, City, County, IBCCP
Agency Name, and Other Agency Name.
The row source for City is: SELECT DISTINCTROW ., .
FROM ;
This allows the values...
|
by: Karl |
last post by:
Using A2000 with 2 tables
Table 1 is a reference table with 2 fields
Table 2 has 2 fields and 2 combo boxes to lookup date in table 1
Combo1 binds to col 1 in table 1, this works OK
Combo 2...
|
by: damonrulz |
last post by:
If I have two combo boxes (Combo1 & Combo2) and when a certain value in Combo1 is selected, the values in Combo2 that correspond with that value will show, and the rest will be hidden.
For...
|
by: mygirl22 |
last post by:
Hi,
I used this code to created 2 combo boxes General and Specific...and Only show Specific (Combo B) when Combo A is chosen.....
What i need now is to know how to assign specific values to the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |