Problem running a query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have 2 Combo boxes in a form. One of the combo boxes is attached directly
to a field in a table. I would like to populate my second combo box according
to which value the user chooses.

To make this I have written the following code.

Dim dbrecs As DAO.Database
Dim rstrecs As DAO.Recordset
Dim STRsql As String


Private Sub cmb_sender_Change()

STRsql = "SELECT Reciever.Rec_Company, Reciever.Rec_Destination_Code,
Reciever.Rec_ID FROM Reciever WHERE Reciever.Shipp_Account = '" &
Me.cmb_sender.Value & "'"

Set rstrecs = dbrecs.OpenRecordset(STRsql, dbOpenDynaset)

However when I try to run this code the followingerror message will come
up:- "Object variable or With block variable not set".

I know this might sound stupid but I am a bit of a newbee here and have
spent a lot of time trying to solve this problem.

Thanks
Gordon
 
Gordon:

I don't know all of your specifics, however, I believe your error is being
generated from the fact that the variable dbrecs has not been set to an
instance of a database. For example, if you want it to refer to the current
database you can add a line such as:

Set dbrecs = CurrentDb

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Hi,

I have 2 Combo boxes in a form. One of the combo boxes is attached directly
to a field in a table. I would like to populate my second combo box
according
to which value the user chooses.

To make this I have written the following code.

Dim dbrecs As DAO.Database
Dim rstrecs As DAO.Recordset
Dim STRsql As String


Private Sub cmb_sender_Change()

STRsql = "SELECT Reciever.Rec_Company, Reciever.Rec_Destination_Code,
Reciever.Rec_ID FROM Reciever WHERE Reciever.Shipp_Account = '" &
Me.cmb_sender.Value & "'"

Set rstrecs = dbrecs.OpenRecordset(STRsql, dbOpenDynaset)

However when I try to run this code the followingerror message will come
up:- "Object variable or With block variable not set".

I know this might sound stupid but I am a bit of a newbee here and have
spent a lot of time trying to solve this problem.

Thanks
Gordon
 
Hi David,

This has solved the problem. Cannot believe I spent all that time for
something this simple. Thanks a lot for your help.

Thanks
Gordon
 
Back
Top