473,386 Members | 1,720 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,386 software developers and data experts.

object variable or with block variable not set

I am encountering an error on the following code. Basically, I have
two queries which I am using to enter new records into two other
tables, one a master and the other a child.

Function Macro3()
On Error GoTo Macro3_Err

Dim dbsCreditCard As Database
Dim rst999 As Recordset
Dim rst999Detail As Recordset
Dim rstAutoPayTo999 As Recordset
Dim rstAutoPayTo999Detail As Recordset

Set dbsCreditCard = CurrentDb()
Set rst999 = dbsCreditCard.OpenRecordset("999", dbOpenDynaset)
Set rst999Detail = dbsCreditCard.OpenRecordset("999Detail",
dbOpenDynaset)
Set rstAutoPayTo999 = dbsCreditCard.OpenRecordset("AutoPay To
999", dbOpenDynaset)
Set rstAutoPay999Detail = dbsCreditCard.OpenRecordset("AutoPay
To 999Detail", dbOpenDynaset)

With rstAutoPayTo999
Do Until .EOF
rst999.AddNew
rst999!Date = rstAutoPayTo999!ReportDate
rst999!userid = "autopay"
rst999.Update

With rstAutoPayTo999Detail
Do Until .EOF '********** ERRORS HERE ***********
rst999Detail.AddNew
rst999Detail!Pro = rstAutoPayTo999Detail!Pro
rst999Detail!Amount = rstAutoPayTo999Detail!Amount
'rst999detail!999Pro = rst999!999pro
'rst999detail!999ProT = rst999!999pro
rst999Detail.Update
.MoveNext
Loop
End With

.MoveNext
Loop
End With

Macro3_Exit:
Exit Function

Macro3_Err:
MsgBox Error$
Resume Macro3_Exit

End Function
I am guessing it is a "Set" issue of some sort, but cannot seem to
figure it out. Any help would be great!

Thanks

Ron

Nov 13 '05 #1
1 2333
ro******@alltel.net wrote in
news:11*********************@f14g2000cwb.googlegro ups.com:
I am encountering an error on the following code. Basically, I
have two queries which I am using to enter new records into two
other tables, one a master and the other a child.
First off, it looks to me like you could be doing the insert with a
SQL statement, instead of needing to open a recordset to do it.

Secondly, I

Function Macro3()
On Error GoTo Macro3_Err

Dim dbsCreditCard As Database
Dim rst999 As Recordset
Dim rst999Detail As Recordset
Dim rstAutoPayTo999 As Recordset
Dim rstAutoPayTo999Detail As Recordset

Set dbsCreditCard = CurrentDb()
Set rst999 = dbsCreditCard.OpenRecordset("999",
dbOpenDynaset) Set rst999Detail =
dbsCreditCard.OpenRecordset("999Detail",
dbOpenDynaset)
Set rstAutoPayTo999 = dbsCreditCard.OpenRecordset("AutoPay
To
999", dbOpenDynaset)
Set rstAutoPay999Detail =
dbsCreditCard.OpenRecordset("AutoPay
To 999Detail", dbOpenDynaset)

With rstAutoPayTo999
Seems to me that right here you need these lines:
If .RecordCount <> 0 Then
.MoveFirst

And then the rest of your code should be inside that If/Then/Else
structure, with an End If at the end.

Two things: if there are no records, you don't want to do anything.

And you can't assume that the current record will be the first
record of your recordset.

Also, I don't think it's a very good idea to nest WITH blocks. Your
outer WITH block is really only used once (for the .EOF). In fact,
that may be the reason you're having the problem. How is the code
supposed to know for certain which parent With it belongs with?
Do Until .EOF
rst999.AddNew
rst999!Date = rstAutoPayTo999!ReportDate
rst999!userid = "autopay"
rst999.Update

With rstAutoPayTo999Detail
Do Until .EOF '********** ERRORS HERE ***********
rst999Detail.AddNew
rst999Detail!Pro = rstAutoPayTo999Detail!Pro
rst999Detail!Amount = rstAutoPayTo999Detail!Amount
'rst999detail!999Pro = rst999!999pro
'rst999detail!999ProT = rst999!999pro
rst999Detail.Update
.MoveNext
Loop
End With

.MoveNext
Loop
End With

Macro3_Exit:
You should clean up all your variables here, with a codeblock like
this for each of your recordset variables:

If Not (rst999 Is Nothing) Then
rst999.Close
Set rst999 = Nothing
End If

And last of all:

Set dbsCreditCard = Nothing

(there's no need to close dbsCreditCard because you can't, as it's
pointing to the current database).
Exit Function

Macro3_Err:
MsgBox Error$
Resume Macro3_Exit

End Function


I don't understand what you're doing here.

It looks like:

For each record in [AutoPay To 999] you are adding a record to
[999].

As well, for each record in [AutoPay To 999] you are adding a record
for each of the records in [AutoPay To 999Detail], using values
drawn from [999Detail].

But what is not at all clear is what the links are between the data
in the source table and in the tables you're adding the data to. I
would expect to see some ID number that joins the detail records to
their parent, but I seen nothing in your code.

So, I can't help much, because I don't really understand what you're
trying to accomplish.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #2

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

Similar topics

24
by: Hung Jung Lu | last post by:
Hi, Does anybody know where this term comes from? "First-class object" means "something passable as an argument in a function call", but I fail to see the connection with "object class" or...
10
by: Michael McCracken | last post by:
Hi, I have a problem with unittest.TestCase that I could really use some help with. I have a class File in module File. The important thing about File for this discussion is that it's simple -...
8
by: Lauren Quantrell | last post by:
I get the following error: "Object variable or Width block variable not set error" trying to run this in my Access2000 .ADP database: CurrentDb.Properties.Append...
8
by: Mark Neilson | last post by:
1. What is the best way to make a single instance of my top level class (DLL) internally available to all other members of the assembly? The top level object is where all other access is made in...
6
by: Neo Geshel | last post by:
I am trying to deal with an image in code-behind. I consistently get the following error: Server Error in '/' Application. Object variable or With block variable not set. Description: An...
44
by: petermichaux | last post by:
Hi, I have been using the following line of code to create an object called "Serious" if it doesn't already exist. if (Serious == null) {var Serious = {};} This works in the scripts I use...
3
by: Richard Hollenbeck | last post by:
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...
1
by: abhijmenbumca07 | last post by:
Object variable or With block variable not set. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
4
by: BrianAdev | last post by:
Why It throw an error of <Object variable or With block variable not set> set objAccess = GetObject(strMdbPath) objAccess.DoCmd.SetWarning False objAccess.DoCmd.OpenReport strReportName, 0 'It...
3
by: Newbie19 | last post by:
I'm trying to get a list of all subfolders in a folder on a share drive, but I keep on getting this error message: Object variable or With block variable not set. Description: An unhandled...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.