473,748 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 cmdAddIngredien tToRecipe_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.lngR ecipeID FROM tblRecipes WHERE
(((tblRecipes.l ngRecipeID)= " & [Forms]![frmRecipes]![lngRecipeID] & "));"

Set rsGetRecipeID = dbGetRecipeID.O penRecordset(St rSQL, dbOpenDynaset)
recipeID = rsGetRecipeID.F ields(0)

Set rsGetRecipeID = Nothing
Set dbGetRecipeID = Nothing

' This works fine to this point

' Get IngredientID for future action query

Dim IngredientID As Long
Dim dbGetIngredient ID As DAO.Database
Dim rsGetIngredient ID 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 = '" & cboIngredientNa me & "'"

'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 rsGetIngredient ID = dbGetIngredient ID.OpenRecordse t(StrSQL,
dbOpenDynaset)
IngredientID = rsGetIngredient ID.Fields(0)

Set rsGetRecipeID = Nothing
Set dbGetRecipeID = Nothing

MsgBox IngredientID 'just to test my code this far.

End Sub
Jun 29 '06 #1
3 35509
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 cmdAddIngredien tToRecipe_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.lngR ecipeID FROM tblRecipes WHERE
(((tblRecipes.l ngRecipeID)= " & [Forms]![frmRecipes]![lngRecipeID] & "));"

Set rsGetRecipeID = dbGetRecipeID.O penRecordset(St rSQL, dbOpenDynaset)
recipeID = rsGetRecipeID.F ields(0)

Set rsGetRecipeID = Nothing
Set dbGetRecipeID = Nothing

' This works fine to this point

' Get IngredientID for future action query

Dim IngredientID As Long
Dim dbGetIngredient ID As DAO.Database
Dim rsGetIngredient ID 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 = '" & cboIngredientNa me & "'"

'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 rsGetIngredient ID = dbGetIngredient ID.OpenRecordse t(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
rsGetIngredient ID object to contain a reference to a recordset. This line depends on
another object - "dbGetIngredien tID".

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.OpenDa tabase(...)

so that would explain the "Object variable is not set" message.
--
'---------------
'John Mishefske
'---------------
Jun 29 '06 #2
"John Mishefske" <jm**********@S PAMyahoo.com> wrote in message
news:hY******** **********@torn ado.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 cmdAddIngredien tToRecipe_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.lngR ecipeID FROM tblRecipes WHERE
(((tblRecipes.l ngRecipeID)= " & [Forms]![frmRecipes]![lngRecipeID] &
"));"

Set rsGetRecipeID = dbGetRecipeID.O penRecordset(St rSQL,
dbOpenDynaset)
recipeID = rsGetRecipeID.F ields(0)

Set rsGetRecipeID = Nothing
Set dbGetRecipeID = Nothing

' This works fine to this point

' Get IngredientID for future action query

Dim IngredientID As Long
Dim dbGetIngredient ID As DAO.Database
Dim rsGetIngredient ID 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 = '" & cboIngredientNa me & "'"

'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 rsGetIngredient ID = dbGetIngredient ID.OpenRecordse t(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
rsGetIngredient ID object to contain a reference to a recordset. This line
depends on another object - "dbGetIngredien tID".

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.OpenDa tabase(...)

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 dbGetIngredient ID = 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.ne t> wrote in message
news:YiJog.6211 $il.3902@trnddc 03...
"John Mishefske" <jm**********@S PAMyahoo.com> wrote in message
news:hY******** **********@torn ado.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
4930
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 filename.py
12
2028
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 it acts like the asp engine is not working.
3
6611
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
2687
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 able to run ActiveX control". So, the ActiveX control just show on the broswer, but not able to run it. I want to find a way to detect it. And prompt the user a message telling
2
3685
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 start will use the existed process. So only one application run. I can use mouse to run this application twice, and there are two A.exe processes in processed pool. So how can i do the same work using code but not manu-click?
2
2902
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 sometimes there is a need to do it on user's demand. I'd like to ensure that I properly understood the method of running DTS I've just found using Google.
7
9075
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 could run simultaneously, but that might break Windows... ;) The problem I had was I couldn't get the files to RUN, only to OPEN. Thanks for the help!!! pseudo-code looks like this
5
8968
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 this cannot be done just from JS? I though I could do it using an OCX active (signed) and then call it from JS using onclick but can't seem to get this to work!
13
4616
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 multiple files as an exe file that can then run the compressed files after unpacking them to a temp folder. The problem is that I have to unpack the files to the hard-disk and then run them from there, making them vulnerable to user that may try to get...
5
1984
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 testout.php
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.