gray
11-03-2007, 11:13 AM
Hi
Access 2002
Win XPPro
Here's an interesting problem for you chaps out there (and girls too, of course!)
I build an Invoice using a report. On it, I have placed a very simple subreport. The subreport has only one textbox in it namely, "Address_Line". The subreport is bound to a "holding" table, "Temp_Risk_Address_Table". This is a very simple table with just two fields: "autonumber" and "Risk_Address_Line".
In the Activate Event of the main form, I run an SQL query to extract the address details to which the Invoice is to be sent. I write these details into the holding table. I empty the table each time by calling "Delete * from etc" before I re-populate it. All works very nicely!
The bit I cannot figure out is this.....
When I request the main report, it dutifully clears down the holding table and adds the correct address details into it perfectly. If I fire up the subreport on it's own, it displays each address line perfectly..... BUT when viewing the Main report, the first row of the subreport appears twice! This confuses me since I have not had a beer!.
If the holding table is populated correctly and the subreport looks fine on it's own, why on earth is the first row of the subreport appearing twice on the main report.... Is it my code? Or maybe the wrong event?
Here's how I populate the holding table in the main report Activate event (it's a little laborious, I know, but I can understand it that way :) ) :-
-------------------------------------------------------------------------
rsWrite.Open "Temp_Risk_Address_Table", CurrentProject.AccessConnection, adOpenDynamic, adLockOptimistic
If Me.Risk_Contact_No_TextBox <> "" Then
rsRead.Open "Contacts", CurrentProject.AccessConnection, adOpenForwardOnly, adLockOptimistic
rsRead.Find "[Contact_No] = '" & Me.Risk_Contact_No_TextBox & "'"
If Not rsRead.EOF Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Full_Name
rsWrite.Update
End If
rsRead.Close
End If
'Grab the values of the various address lines
If Me.Risk_Address_Unique_No_TextBox <> "" Then
rsRead.Open "Contact_Addresses", CurrentProject.AccessConnection, adOpenForwardOnly, adLockOptimistic
rsRead.Find "[Address_Unique_No] = '" & Me.Risk_Address_Unique_No_TextBox & "'"
If Not rsRead.EOF Then
If Not rsRead!Contact_Address_Line1 = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Address_Line1
rsWrite.Update
End If
If Not rsRead!Contact_Address_Line2 = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Address_Line2
rsWrite.Update
End If
If Not rsRead!Contact_Address_Line3 = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Address_Line3
rsWrite.Update
End If
If Not rsRead!Contact_Address_Line4 = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Address_Line4
rsWrite.Update
End If
If Not rsRead!Contact_Address_Line5 = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Address_Line5
rsWrite.Update
End If
If Not rsRead!Contact_Post_Code = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Post_Code
rsWrite.Update
End If
End If
rsRead.Close
End If
rsWrite.Close
-------------------------------------------------------------------
Your help is, as always, much appreciated
Access 2002
Win XPPro
Here's an interesting problem for you chaps out there (and girls too, of course!)
I build an Invoice using a report. On it, I have placed a very simple subreport. The subreport has only one textbox in it namely, "Address_Line". The subreport is bound to a "holding" table, "Temp_Risk_Address_Table". This is a very simple table with just two fields: "autonumber" and "Risk_Address_Line".
In the Activate Event of the main form, I run an SQL query to extract the address details to which the Invoice is to be sent. I write these details into the holding table. I empty the table each time by calling "Delete * from etc" before I re-populate it. All works very nicely!
The bit I cannot figure out is this.....
When I request the main report, it dutifully clears down the holding table and adds the correct address details into it perfectly. If I fire up the subreport on it's own, it displays each address line perfectly..... BUT when viewing the Main report, the first row of the subreport appears twice! This confuses me since I have not had a beer!.
If the holding table is populated correctly and the subreport looks fine on it's own, why on earth is the first row of the subreport appearing twice on the main report.... Is it my code? Or maybe the wrong event?
Here's how I populate the holding table in the main report Activate event (it's a little laborious, I know, but I can understand it that way :) ) :-
-------------------------------------------------------------------------
rsWrite.Open "Temp_Risk_Address_Table", CurrentProject.AccessConnection, adOpenDynamic, adLockOptimistic
If Me.Risk_Contact_No_TextBox <> "" Then
rsRead.Open "Contacts", CurrentProject.AccessConnection, adOpenForwardOnly, adLockOptimistic
rsRead.Find "[Contact_No] = '" & Me.Risk_Contact_No_TextBox & "'"
If Not rsRead.EOF Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Full_Name
rsWrite.Update
End If
rsRead.Close
End If
'Grab the values of the various address lines
If Me.Risk_Address_Unique_No_TextBox <> "" Then
rsRead.Open "Contact_Addresses", CurrentProject.AccessConnection, adOpenForwardOnly, adLockOptimistic
rsRead.Find "[Address_Unique_No] = '" & Me.Risk_Address_Unique_No_TextBox & "'"
If Not rsRead.EOF Then
If Not rsRead!Contact_Address_Line1 = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Address_Line1
rsWrite.Update
End If
If Not rsRead!Contact_Address_Line2 = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Address_Line2
rsWrite.Update
End If
If Not rsRead!Contact_Address_Line3 = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Address_Line3
rsWrite.Update
End If
If Not rsRead!Contact_Address_Line4 = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Address_Line4
rsWrite.Update
End If
If Not rsRead!Contact_Address_Line5 = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Address_Line5
rsWrite.Update
End If
If Not rsRead!Contact_Post_Code = "" Then
rsWrite.AddNew
rsWrite!Risk_Address_Line = rsRead!Contact_Post_Code
rsWrite.Update
End If
End If
rsRead.Close
End If
rsWrite.Close
-------------------------------------------------------------------
Your help is, as always, much appreciated