473,499 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2337
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
6709
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
1800
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
8860
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
1809
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
4225
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
3310
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
35487
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
2270
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
3462
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
3241
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
7132
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
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7223
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...
1
6899
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...
0
7390
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
5475
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,...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1427
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 ...
0
302
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...

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.