473,396 Members | 2,013 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,396 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 35479
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...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.