473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Run-time error 91 Object Variable or With block variable not set

I've marked the line in this subroutine where I've been getting this error.
It may be something stupid but I've been staring at this error trying to fix
it for over an hour. I'm pretty sure the table and field names and controls
are all named correctly, and the control referred to in the errant code is
open, and it has data in it.

Private Sub cmdAddIngredientToRecipe_Click()

' Get RecipeID for future action query
Dim recipeID As Long
Dim dbGetRecipeID As DAO.Database
Dim rsGetRecipeID As DAO.Recordset
Dim StrSQL As String
Set dbGetRecipeID = CurrentDb()

StrSQL = "SELECT tblRecipes.lngRecipeID FROM tblRecipes WHERE
(((tblRecipes.lngRecipeID)= " & [Forms]![frmRecipes]![lngRecipeID] & "));"

Set rsGetRecipeID = dbGetRecipeID.OpenRecordset(StrSQL, dbOpenDynaset)
recipeID = rsGetRecipeID.Fields(0)

Set rsGetRecipeID = Nothing
Set dbGetRecipeID = Nothing

' This works fine to this point

' Get IngredientID for future action query

Dim IngredientID As Long
Dim dbGetIngredientID As DAO.Database
Dim rsGetIngredientID As DAO.Recordset

'I'm filling variables to use in an append query down later in this
subroutine.

StrSQL = "SELECT tblIngredients.lngIngredientID FROM tblIngredients
WHERE tblIngredients.IngredientName = '" & cboIngredientName & "'"

'IngredientName is a text field.

' The next line is flagged as a problem. I get a run-time error 91" Object
Variable
' or with block variable not set. I'm predicting something is wrong with my
SQL statament on the previous line.

Set rsGetIngredientID = dbGetIngredientID.OpenRecordset(StrSQL,
dbOpenDynaset)
IngredientID = rsGetIngredientID.Fields(0)

Set rsGetRecipeID = Nothing
Set dbGetRecipeID = Nothing

MsgBox IngredientID 'just to test my code this far.

End Sub
Jun 29 '06 #1
3 35472
Richard Hollenbeck wrote:
I've marked the line in this subroutine where I've been getting this error.
It may be something stupid but I've been staring at this error trying to fix
it for over an hour. I'm pretty sure the table and field names and controls
are all named correctly, and the control referred to in the errant code is
open, and it has data in it.

Private Sub cmdAddIngredientToRecipe_Click()

' Get RecipeID for future action query
Dim recipeID As Long
Dim dbGetRecipeID As DAO.Database
Dim rsGetRecipeID As DAO.Recordset
Dim StrSQL As String
Set dbGetRecipeID = CurrentDb()

StrSQL = "SELECT tblRecipes.lngRecipeID FROM tblRecipes WHERE
(((tblRecipes.lngRecipeID)= " & [Forms]![frmRecipes]![lngRecipeID] & "));"

Set rsGetRecipeID = dbGetRecipeID.OpenRecordset(StrSQL, dbOpenDynaset)
recipeID = rsGetRecipeID.Fields(0)

Set rsGetRecipeID = Nothing
Set dbGetRecipeID = Nothing

' This works fine to this point

' Get IngredientID for future action query

Dim IngredientID As Long
Dim dbGetIngredientID As DAO.Database
Dim rsGetIngredientID As DAO.Recordset

'I'm filling variables to use in an append query down later in this
subroutine.

StrSQL = "SELECT tblIngredients.lngIngredientID FROM tblIngredients
WHERE tblIngredients.IngredientName = '" & cboIngredientName & "'"

'IngredientName is a text field.

' The next line is flagged as a problem. I get a run-time error 91" Object
Variable
' or with block variable not set. I'm predicting something is wrong with my
SQL statament on the previous line.

Set rsGetIngredientID = dbGetIngredientID.OpenRecordset(StrSQL,
dbOpenDynaset)


The 91 error is indicating that an object variable is not set to a value, i.e. it is
"Nothing".

Looking at the line where the error occurs shows that you are setting the
rsGetIngredientID object to contain a reference to a recordset. This line depends on
another object - "dbGetIngredientID".

Looking at the code I see that this is defined with:

Dim dbGetRecipeID As DAO.Database

so it is defined to be a reference to a DAO Database object. However, I don't see where
you actually instantiated this object; i.e. you don't have a line like:

Set dbGetRecipeID = CurrentDb()

or

Set dbGetRecipeID = dbEngine.OpenDatabase(...)

so that would explain the "Object variable is not set" message.
--
'---------------
'John Mishefske
'---------------
Jun 29 '06 #2
"John Mishefske" <jm**********@SPAMyahoo.com> wrote in message
news:hY******************@tornado.rdc-kc.rr.com...
Richard Hollenbeck wrote:
I've marked the line in this subroutine where I've been getting this
error. It may be something stupid but I've been staring at this error
trying to fix it for over an hour. I'm pretty sure the table and field
names and controls are all named correctly, and the control referred to
in the errant code is open, and it has data in it.

Private Sub cmdAddIngredientToRecipe_Click()

' Get RecipeID for future action query
Dim recipeID As Long
Dim dbGetRecipeID As DAO.Database
Dim rsGetRecipeID As DAO.Recordset
Dim StrSQL As String
Set dbGetRecipeID = CurrentDb()

StrSQL = "SELECT tblRecipes.lngRecipeID FROM tblRecipes WHERE
(((tblRecipes.lngRecipeID)= " & [Forms]![frmRecipes]![lngRecipeID] &
"));"

Set rsGetRecipeID = dbGetRecipeID.OpenRecordset(StrSQL,
dbOpenDynaset)
recipeID = rsGetRecipeID.Fields(0)

Set rsGetRecipeID = Nothing
Set dbGetRecipeID = Nothing

' This works fine to this point

' Get IngredientID for future action query

Dim IngredientID As Long
Dim dbGetIngredientID As DAO.Database
Dim rsGetIngredientID As DAO.Recordset

'I'm filling variables to use in an append query down later in this
subroutine.

StrSQL = "SELECT tblIngredients.lngIngredientID FROM tblIngredients
WHERE tblIngredients.IngredientName = '" & cboIngredientName & "'"

'IngredientName is a text field.

' The next line is flagged as a problem. I get a run-time error 91"
Object Variable
' or with block variable not set. I'm predicting something is wrong with
my SQL statament on the previous line.

Set rsGetIngredientID = dbGetIngredientID.OpenRecordset(StrSQL,
dbOpenDynaset)


The 91 error is indicating that an object variable is not set to a value,
i.e. it is "Nothing".

Looking at the line where the error occurs shows that you are setting the
rsGetIngredientID object to contain a reference to a recordset. This line
depends on another object - "dbGetIngredientID".

Looking at the code I see that this is defined with:

Dim dbGetRecipeID As DAO.Database

so it is defined to be a reference to a DAO Database object. However, I
don't see where you actually instantiated this object; i.e. you don't have
a line like:

Set dbGetRecipeID = CurrentDb()

or

Set dbGetRecipeID = dbEngine.OpenDatabase(...)

so that would explain the "Object variable is not set" message.
--
'---------------
'John Mishefske
'---------------


Thank you. That at least changed something. I added the code:
"Set dbGetIngredientID = CurrentDb()" without the quotes just before the
second SQL statement. Now I'm not getting that error 91 anymore. Now I'm
getting error 3021, "no current record". But the related forms are open and
pointed at valid records. Hey at this point any change is progress. :-)
I'll double check that my practice query (that works by the way) is closed
then try again.

Jun 29 '06 #3
"Richard Hollenbeck" <ri****************@verizon.net> wrote in message
news:YiJog.6211$il.3902@trnddc03...
"John Mishefske" <jm**********@SPAMyahoo.com> wrote in message
news:hY******************@tornado.rdc-kc.rr.com...
Richard Hollenbeck wrote:


Problem solved. In addition to forgetting to set the db as the currentdb(),
I was looking for a single value but had multiple columns in the combobox.
Fixed that and everything went well after that. Now on to the next problem.
I'll try to figure it out first.

Thanks for all the help.

Rich
Jun 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: leroybt.rm | last post by:
Can someone tell me how to run a script from a interactive shell I type the following: >>>python filename >>>python filename.py >>>run filename >>>run filename.py >>>/run filename >>>/run...
12
by: Mactash | last post by:
Folks, I am trying just to run a simple asp commands in the Internet Explorer. ( I have windows XP) When I run this asp lines on ASP Matrix web server it is ok. But, when I run this on IIS...
3
by: PW | last post by:
How can I run a DOS command from my ASP ? (prefer to use html/vbscript solution rather than 3rd party add-ons)
4
by: SiuLoBow | last post by:
Hi, Is there anyway to detect the ActiveX control is able to run on the browser or not? After I installed the ActiveX control to my system, user sometimes switch the secruity setting to "not...
2
by: Napo | last post by:
Hi: i build a .net application named A.exe. I need run this application twice using c# code in another application. i try to use process.start(A.exe) twcie, but it failed. Because the second...
2
by: Piotr Lipski | last post by:
I have two servers: progress as transational server and mssql as warehouse server. I did DTS that "pumps" data from progress to mssql (via ODBC). Copying the data has to be done once a day, but...
7
by: erniedude | last post by:
Hi, I'm a newbie and I was wondering if anyone knew a (Python) script to run 4 batch files, one after the other (assuming the directories are known). It would be better if all 4 batch files...
5
by: Adrian | last post by:
Hi I want to be able to start a locally installed application from within a web page. So if our application is installed it is started when a user clicks a link on our page. I know or assume...
13
by: Nemok | last post by:
Hi, Is it possible in anyway to load a file into memory and then run it from there? I am working on a file compressor (www.nemokprod.go.ro/nb.htm) that can compress and encrypt and save...
5
by: nephish | last post by:
hey there all, i have been looking for a way to run a php command line script from my python script. here is what i want to do: if x = 4: execute php4 testin.php else: execute php4...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.