Using VBA to control combo-box rowsource - Trouble

RiskyP

Registered User.
Local time
Today, 15:51
Joined
Jan 3, 2013
Messages
27
Hello,

I am getting rather fusrtated - I have built a form including 2 comboboxes. the frist combobox uses an SQL query to select rowsource from my master table fine - however the second combobox recordset will vary depending what is entered in the first combobox. I have written a marco set in the 'on exit' event from the first combobox it goes like this;

Code:
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Dim mySql As String
mySql = "SELECT DISTINCT [Vessel In Date] FROM [Master Table - Packages] WHERE ([Master Table - Packages].[Vessel Name] =" & Me.Vessel_Name & ")"
Set rs = db.OpenRecordset(mySql)
Me.Vessel_In_Date.Recordset = rs

the problem is - i keep getting an error using this - why would that be?

Any help would be greatly appreciated
Thanks
P
 



Thanks soo much - was slecting .Recordset rather than .Rowsource

For anyone else -> Code now looks (with un-needed trimming)
Code:
Dim mySql As String
mySql = "SELECT DISTINCT [Vessel In Date] FROM [Master Table - Packages] WHERE ([Vessel Name] ='" & Me.Vessel_Name & "')"
Me.Vessel_In_Date.RowSource = mySql
 

Users who are viewing this thread

Back
Top Bottom