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 rstAutoPayTo999 Detail As Recordset
Set dbsCreditCard = CurrentDb()
Set rst999 = dbsCreditCard.O penRecordset("9 99", dbOpenDynaset)
Set rst999Detail = dbsCreditCard.O penRecordset("9 99Detail",
dbOpenDynaset)
Set rstAutoPayTo999 = dbsCreditCard.O penRecordset("A utoPay To
999", dbOpenDynaset)
Set rstAutoPay999De tail = dbsCreditCard.O penRecordset("A utoPay
To 999Detail", dbOpenDynaset)
With rstAutoPayTo999
Do Until .EOF
rst999.AddNew
rst999!Date = rstAutoPayTo999 !ReportDate
rst999!userid = "autopay"
rst999.Update
With rstAutoPayTo999 Detail
Do Until .EOF '********** ERRORS HERE ***********
rst999Detail.Ad dNew
rst999Detail!Pr o = rstAutoPayTo999 Detail!Pro
rst999Detail!Am ount = rstAutoPayTo999 Detail!Amount
'rst999detail!9 99Pro = rst999!999pro
'rst999detail!9 99ProT = rst999!999pro
rst999Detail.Up date
.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 1 2353 ro******@alltel .net wrote in
news:11******** *************@f 14g2000cwb.goog legroups.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 rstAutoPayTo999 Detail As Recordset
Set dbsCreditCard = CurrentDb() Set rst999 = dbsCreditCard.O penRecordset("9 99", dbOpenDynaset) Set rst999Detail = dbsCreditCard.O penRecordset("9 99Detail", dbOpenDynaset) Set rstAutoPayTo999 = dbsCreditCard.O penRecordset("A utoPay To 999", dbOpenDynaset) Set rstAutoPay999De tail = dbsCreditCard.O penRecordset("A utoPay 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 rstAutoPayTo999 Detail Do Until .EOF '********** ERRORS HERE *********** rst999Detail.Ad dNew rst999Detail!Pr o = rstAutoPayTo999 Detail!Pro rst999Detail!Am ount = rstAutoPayTo999 Detail!Amount 'rst999detail!9 99Pro = rst999!999pro 'rst999detail!9 99ProT = rst999!999pro rst999Detail.Up date .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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 with "first-class airplane ticket". I just find the name a bit
strange. Also, if there are first-class objects, what would the
second-class objects or economy/tourist class objects be? :)
|
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 - no pool of objects are involved,
and subsequent invocations of File.File('filename') should return
distinct objects (and indeed, they do on the command line). Also,
__repr__ prints out the value of id(self) for File, so I can tell
what's going on...
|
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
CurrentDb.CreateProperty(myPropertyName, dbLong, myValue)
Any ideas why and how to fix would be appreciated.
lq
|
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 to the program. Where and
how do I declare and initialise this object?
For instance, it would have property implementation like this:
//*******************************************
public MyClass1 Class1
{
|
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 unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object variable...
| |
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 it but but www.jslint.com is not happy
with me.
|
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 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
|
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 about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object variable or With block variable not set.
Source Error:
Line 305: Me.txt_amount.Text = mat(0)
Line 306: ...
|
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 is fine until now
objAccess.Application.Run "Function",Arg1,Arg2
'Throw the arror
<Object variable or With block variable not set>
|
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 exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object variable or With block...
|
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...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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,...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |