1fde7 Duplicate records in a subform
Sign Up |  Live StatsLive Stats    Articles 37,346| Comments 177,365| Members 19,421, Newest ishpreet| Online 432
Home Contact
 (Forgotten?): 
    Sikhism
    For best SPN experience, use Firefox Internet Browser!


                                                                   Your Banner Here!    




Click Here to Register/Sign Up Daily Hukamnama Member Blogs Downloads Website Navigation Help Fonts Tags

Duplicate records in a subform

Our Donation Goal : Why Donate? : Donate Today! : Donate Anonymously (ਗੁਪਤ) : Our Family of Supporters
Goal this month: 500 USD, Received: 115 USD (23%)
Please Donate...
     
Related Topics...
Thread Thread Starter Forum Replies Last Post
Counts records in a subform Jason Information Technology 2 28-Jul-2006 08:42 AM
Query Duplicate Records & Dates sgyvln Information Technology 2 28-Jul-2006 08:32 AM
RE: Number of records in a subform Ofer Cohen Information Technology 0 28-Jul-2006 08:24 AM
duplicate certain records in 2 linked tables Manny Information Technology 1 28-Jul-2006 08:07 AM
How do I remove duplicate records from a table? CyberQban Information Technology 2 28-Jul-2006 08:04 AM


Tags
duplicate, records, subform
Reply Post New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!
  #1 (permalink)  
Old 08-Nov-2005, 12:53 PM
Barry's Avatar Barry
Guest
 
Posts: n/a
   
   
Duplicate records in a subform

  Donate Today!   Email to Friend  Tell a Friend   Show Printable Version  Print   Contact sikhphilosophy.net Administraion for any Suggestions, Ideas, Feedback.  Feedback  

Register to Remove Advertisements
I have a form (formA) with a subform (formB) inside formA.
I need to duplicate the record in formA which is not a problem but i also
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/information-technology/6856-duplicate-records-in-a-subform.html
want to duplicate the current record in formB at the same time without having
to place another duplicate button in this form.

Can anyone help me with this?

*







Got anything to share on This Topic? Why not share your immediate thoughts/reaction with us! Login Now! or Sign Up Today! to share your views... Gurfateh!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-Nov-2005, 12:53 PM
Allen Browne's Avatar Allen Browne
Guest
 
Posts: n/a
   
   
Re: Duplicate records in a subform

The example below duplicates the invoice record in the main form and the
line items from the subform.

It illustrates 2 techniques:
- The main record is duplciated in the form's RecordsetClone (using DAO).
This gives you to new primary key value, which you need for the related
records.

- The child records are duplicated by executing an append query statement.
This creates them all in one pass.

The code then displays the newly created duplicate.

Private Sub cmdDupe_Click()
Dim strSql As String
Dim db As DAO.Database
Dim lngInvID As Long

Set db = DBEngine(0)(0)

If Me.Dirty Then 'Save first.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
Else

'Duplicate the main record
With Me.RecordsetClone
.AddNew
!InvoiceDate = Date
!ClientID = Me.ClientID
'etc for other fields.
.Update
.Bookmark = .LastModified
lngInvID = !InvoiceID

'Duplicate the related records.
If Me.fInvoiceDetail.Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO tInvoiceDetail ( InvoiceID, Item,
Amount ) " & _
"SELECT " & lngInvID & " As NewInvoiceID,
tInvoiceDetail.Item, " & _
"tInvoiceDetail.Amount FROM tInvoiceDetail " & _
"WHERE (tInvoiceDetail.InvoiceID = " & Me.InvoiceID &
");"
db.Execute strSql, dbFailOnError
Else
MsgBox "Main record duplicated, but there were no related
records."
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
End If

'Display the duplicate.
Me.Bookmark = .LastModified
End With
End If

Set db = Nothing
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Barry" wrote in message
news:FD587861-DD2F-49D4-95E9-4CE4C0450729@microsoft.com...
>I have a form (formA) with a subform (formB) inside formA.
> I need to duplicate the record in formA which is not a problem but i also
> want to duplicate the current record in formB at the same time without
> having
> to place another duplicate button in this form.
>
> Can anyone help me with this?



Reply With Quote
  #3 (permalink)  
Old 09-Nov-2005, 17:50 PM
Allen Browne's Avatar Allen Browne
Guest
 
Posts: n/a
   
   
Re: Duplicate records in a subform

Barry, this gets asked fairly often, so have created a web page explaining
the technique, and illustrating it with code that works with Northwind.

The article is:
Duplicate the record in form and subform
at:
http://allenbrowne.com/ser-57.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856

"Allen Browne" wrote in message
> "Barry" wrote in message
> news:FD587861-DD2F-49D4-95E9-4CE4C0450729@microsoft.com...
>>I have a form (formA) with a subform (formB) inside formA.
>> I need to duplicate the record in formA which is not a problem but i also
>> want to duplicate the current record in formB at the same time without
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
>> having to place another duplicate button in this form.



Reply With Quote
  #4 (permalink)  
Old 09-Nov-2005, 17:50 PM
Barry's Avatar Barry
Guest
 
Posts: n/a
   
   
Re: Duplicate records in a subform

Thanks allen the code has helped me alot and with the explanation i should
now be able to get this working for me.

Thanks

"Allen Browne" wrote:

> Barry, this gets asked fairly often, so have created a web page explaining
> the technique, and illustrating it with code that works with Northwind.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
>
> The article is:
> Duplicate the record in form and subform
> at:
> http://allenbrowne.com/ser-57.html
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Allen Browne" wrote in message
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
> > "Barry" wrote in message
> > news:FD587861-DD2F-49D4-95E9-4CE4C0450729@microsoft.com...
> >>I have a form (formA) with a subform (formB) inside formA.
> >> I need to duplicate the record in formA which is not a problem but i also
> >> want to duplicate the current record in formB at the same time without
> >> having to place another duplicate button in this form.

>
>
>

Reply With Quote
  #5 (permalink)  
Old 09-Nov-2005, 17:50 PM
Barry's Avatar Barry
Guest
 
Posts: n/a
   
   
Re: Duplicate records in a subform

I have a problem with this code

it stops at the line DBEngine(0)(0).Execute strSql, dbFailOnError and gives
an
error message "Syntax error in INSERT INTO statement"

dbFailOnError has a value of 128 if this helps



"Allen Browne" wrote:

> The example below duplicates the invoice record in the main form and the
> line items from the subform.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
>
> It illustrates 2 techniques:
> - The main record is duplciated in the form's RecordsetClone (using DAO).
> This gives you to new primary key value, which you need for the related
> records.
>
> - The child records are duplicated by executing an append query statement.
> This creates them all in one pass.
>
> The code then displays the newly created duplicate.
>
> Private Sub cmdDupe_Click()
> Dim strSql As String
> Dim db As DAO.Database
> Dim lngInvID As Long
>
> Set db = DBEngine(0)(0)
>
> If Me.Dirty Then 'Save first.
> Me.Dirty = False
> End If
> If Me.NewRecord Then
> MsgBox "Select the record to duplicate."
> Else
>
> 'Duplicate the main record
> With Me.RecordsetClone
> .AddNew
> !InvoiceDate = Date
> !ClientID = Me.ClientID
> 'etc for other fields.
> .Update
> .Bookmark = .LastModified
> lngInvID = !InvoiceID
>
> 'Duplicate the related records.
> If Me.fInvoiceDetail.Form.RecordsetClone.RecordCount > 0 Then
> strSql = "INSERT INTO tInvoiceDetail ( InvoiceID, Item,
> Amount ) " & _
> "SELECT " & lngInvID & " As NewInvoiceID,
> tInvoiceDetail.Item, " & _
> "tInvoiceDetail.Amount FROM tInvoiceDetail " & _
> "WHERE (tInvoiceDetail.InvoiceID = " & Me.InvoiceID &
> ");"
> db.Execute strSql, dbFailOnError
> Else
> MsgBox "Main record duplicated, but there were no related
> records."
> End If
>
> 'Display the duplicate.
> Me.Bookmark = .LastModified
> End With
> End If
>
> Set db = Nothing
> End Sub
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Barry" wrote in message
> news:FD587861-DD2F-49D4-95E9-4CE4C0450729@microsoft.com...
> >I have a form (formA) with a subform (formB) inside formA.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
> > I need to duplicate the record in formA which is not a problem but i also
> > want to duplicate the current record in formB at the same time without
> > having
> > to place another duplicate button in this form.
> >
> > Can anyone help me with this?

>
>
>

Reply With Quote
  #6 (permalink)  
Old 09-Nov-2005, 17:51 PM
Allen Browne's Avatar Allen Browne
Guest
 
Posts: n/a
   
   
Re: Duplicate records in a subform

The message indicates that you SQL string is not correct.

Immediately above the dbEngine... line, add this line:
Debug.Print strSQL
Run the code.
When if fails, open the Immediate Window (Ctrl+G).
Can you see what's wrong with the statement? E.g.:
- Spaces missing?
- No value where you expected one?
- Wrong field names?
- Field or table names that contain spaces, that were not in square
brackets?

Mock up a dummy query to compare it to if that helps.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Barry" wrote in message
news:448C0515-B211-49BF-9936-1FDF6935B247@microsoft.com...
>I have a problem with this code
>
> it stops at the line DBEngine(0)(0).Execute strSql, dbFailOnError and
> gives
> an
> error message "Syntax error in INSERT INTO statement"
>
> dbFailOnError has a value of 128 if this helps
>
>
>
> "Allen Browne" wrote:
>
>> The example below duplicates the invoice record in the main form and the
>> line items from the subform.
>>
>> It illustrates 2 techniques:
>> - The main record is duplciated in the form's RecordsetClone (using DAO).
>> This gives you to new primary key value, which you need for the related
>> records.
>>
>> - The child records are duplicated by executing an append query
>> statement.
>> This creates them all in one pass.
>>
>> The code then displays the newly created duplicate.
>>
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
>> Private Sub cmdDupe_Click()
>> Dim strSql As String
>> Dim db As DAO.Database
>> Dim lngInvID As Long
>>
>> Set db = DBEngine(0)(0)
>>
>> If Me.Dirty Then 'Save first.
>> Me.Dirty = False
>> End If
>> If Me.NewRecord Then
>> MsgBox "Select the record to duplicate."
>> Else
>>
>> 'Duplicate the main record
>> With Me.RecordsetClone
>> .AddNew
>> !InvoiceDate = Date
>> !ClientID = Me.ClientID
>> 'etc for other fields.
>> .Update
>> .Bookmark = .LastModified
>> lngInvID = !InvoiceID
>>
>> 'Duplicate the related records.
>> If Me.fInvoiceDetail.Form.RecordsetClone.RecordCount > 0 Then
>> strSql = "INSERT INTO tInvoiceDetail ( InvoiceID, Item,
>> Amount ) " & _
>> "SELECT " & lngInvID & " As NewInvoiceID,
>> tInvoiceDetail.Item, " & _
>> "tInvoiceDetail.Amount FROM tInvoiceDetail " & _
>> "WHERE (tInvoiceDetail.InvoiceID = " & Me.InvoiceID &
>> ");"
>> db.Execute strSql, dbFailOnError
>> Else
>> MsgBox "Main record duplicated, but there were no related
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
>> records."
>> End If
>>
>> 'Display the duplicate.
>> Me.Bookmark = .LastModified
>> End With
>> End If
>>
>> Set db = Nothing
>> End Sub
>>
>> "Barry" wrote in message
>> news:FD587861-DD2F-49D4-95E9-4CE4C0450729@microsoft.com...
>> >I have a form (formA) with a subform (formB) inside formA.
>> > I need to duplicate the record in formA which is not a problem but i
>> > also
>> > want to duplicate the current record in formB at the same time without
>> > having
>> > to place another duplicate button in this form.
>> >
>> > Can anyone help me with this?



Reply With Quote
  #7 (permalink)  
Old 09-Nov-2005, 17:51 PM
Barry's Avatar Barry
Guest
 
Posts: n/a
   
   
Re: Duplicate records in a subform

i am not sure what the "NewID" is in the statement
"SELECT " & lngID & " As NewID

is this a function that is being called or should this be a field in the table



"Allen Browne" wrote:

> The message indicates that you SQL string is not correct.
>
> Immediately above the dbEngine... line, add this line:
> Debug.Print strSQL
> Run the code.
> When if fails, open the Immediate Window (Ctrl+G).
> Can you see what's wrong with the statement? E.g.:
> - Spaces missing?
> - No value where you expected one?
> - Wrong field names?
> - Field or table names that contain spaces, that were not in square
> brackets?
>
> Mock up a dummy query to compare it to if that helps.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Barry" wrote in message
> news:448C0515-B211-49BF-9936-1FDF6935B247@microsoft.com...
> >I have a problem with this code
> >
> > it stops at the line DBEngine(0)(0).Execute strSql, dbFailOnError and
> > gives
> > an
> > error message "Syntax error in INSERT INTO statement"
> >
> > dbFailOnError has a value of 128 if this helps
> >
> >
> >
> > "Allen Browne" wrote:
> >
> >> The example below duplicates the invoice record in the main form and the
> >> line items from the subform.
> >>
> >> It illustrates 2 techniques:
> >> - The main record is duplciated in the form's RecordsetClone (using DAO).
> >> This gives you to new primary key value, which you need for the related
> >> records.
> >>
> >> - The child records are duplicated by executing an append query
> >> statement.
> >> This creates them all in one pass.
> >>
> >> The code then displays the newly created duplicate.
> >>
> >> Private Sub cmdDupe_Click()
> >> Dim strSql As String
> >> Dim db As DAO.Database
> >> Dim lngInvID As Long
> >>
> >> Set db = DBEngine(0)(0)
> >>
> >> If Me.Dirty Then 'Save first.
> >> Me.Dirty = False
> >> End If
> >> If Me.NewRecord Then
> >> MsgBox "Select the record to duplicate."
> >> Else
> >>
> >> 'Duplicate the main record
> >> With Me.RecordsetClone
> >> .AddNew
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
> >> !InvoiceDate = Date
> >> !ClientID = Me.ClientID
> >> 'etc for other fields.
> >> .Update
> >> .Bookmark = .LastModified
> >> lngInvID = !InvoiceID
> >>
> >> 'Duplicate the related records.
> >> If Me.fInvoiceDetail.Form.RecordsetClone.RecordCount > 0 Then
> >> strSql = "INSERT INTO tInvoiceDetail ( InvoiceID, Item,
> >> Amount ) " & _
> >> "SELECT " & lngInvID & " As NewInvoiceID,
> >> tInvoiceDetail.Item, " & _
> >> "tInvoiceDetail.Amount FROM tInvoiceDetail " & _
> >> "WHERE (tInvoiceDetail.InvoiceID = " & Me.InvoiceID &
> >> ");"
> >> db.Execute strSql, dbFailOnError
> >> Else
> >> MsgBox "Main record duplicated, but there were no related
> >> records."
> >> End If
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
> >>
> >> 'Display the duplicate.
> >> Me.Bookmark = .LastModified
> >> End With
> >> End If
> >>
> >> Set db = Nothing
> >> End Sub
> >>
> >> "Barry" wrote in message
> >> news:FD587861-DD2F-49D4-95E9-4CE4C0450729@microsoft.com...
> >> >I have a form (formA) with a subform (formB) inside formA.
> >> > I need to duplicate the record in formA which is not a problem but i
> >> > also
> >> > want to duplicate the current record in formB at the same time without
> >> > having
> >> > to place another duplicate button in this form.
> >> >
> >> > Can anyone help me with this?

>
>
>

Reply With Quote
  #8 (permalink)  
Old 09-Nov-2005, 17:51 PM
Allen Browne's Avatar Allen Browne
Guest
 
Posts: n/a
   
   
Re: Duplicate records in a subform

NewId is just the alias for the number.
You could call it anything at all.
The statement should end up as:
SELECT 789 AS YNotThisName, ...

What matters is that the items in the SELECT clause match the same fields as
those inside the brackets in the INSERT clause.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Barry" wrote in message
news:0BF15F7F-C0C0-49E2-B349-D50A609E6A88@microsoft.com...
>i am not sure what the "NewID" is in the statement
> "SELECT " & lngID & " As NewID
>
> is this a function that is being called or should this be a field in the
> table
>
>
>
> "Allen Browne" wrote:
>
>> The message indicates that you SQL string is not correct.
>>
>> Immediately above the dbEngine... line, add this line:
>> Debug.Print strSQL
>> Run the code.
>> When if fails, open the Immediate Window (Ctrl+G).
>> Can you see what's wrong with the statement? E.g.:
>> - Spaces missing?
>> - No value where you expected one?
>> - Wrong field names?
>> - Field or table names that contain spaces, that were not in square
>> brackets?
>>
>> Mock up a dummy query to compare it to if that helps.
>>
>> "Barry" wrote in message
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
>> news:448C0515-B211-49BF-9936-1FDF6935B247@microsoft.com...
>> >I have a problem with this code
>> >
>> > it stops at the line DBEngine(0)(0).Execute strSql, dbFailOnError and
>> > gives
>> > an
>> > error message "Syntax error in INSERT INTO statement"
>> >
>> > dbFailOnError has a value of 128 if this helps
>> >
>> >
>> >
>> > "Allen Browne" wrote:
>> >
>> >> The example below duplicates the invoice record in the main form and
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
>> >> the
>> >> line items from the subform.
>> >>
>> >> It illustrates 2 techniques:
>> >> - The main record is duplciated in the form's RecordsetClone (using
>> >> DAO).
>> >> This gives you to new primary key value, which you need for the
>> >> related
>> >> records.
>> >>
>> >> - The child records are duplicated by executing an append query
>> >> statement.
>> >> This creates them all in one pass.
>> >>
>> >> The code then displays the newly created duplicate.
>> >>
>> >> Private Sub cmdDupe_Click()
>> >> Dim strSql As String
>> >> Dim db As DAO.Database
>> >> Dim lngInvID As Long
>> >>
>> >> Set db = DBEngine(0)(0)
>> >>
>> >> If Me.Dirty Then 'Save first.
>> >> Me.Dirty = False
>> >> End If
>> >> If Me.NewRecord Then
>> >> MsgBox "Select the record to duplicate."
>> >> Else
>> >>
>> >> 'Duplicate the main record
>> >> With Me.RecordsetClone
>> >> .AddNew
>> >> !InvoiceDate = Date
>> >> !ClientID = Me.ClientID
>> >> 'etc for other fields.
>> >> .Update
>> >> .Bookmark = .LastModified
>> >> lngInvID = !InvoiceID
>> >>
>> >> 'Duplicate the related records.
>> >> If Me.fInvoiceDetail.Form.RecordsetClone.RecordCount > 0
>> >> Then
>> >> strSql = "INSERT INTO tInvoiceDetail ( InvoiceID,
>> >> Item,
>> >> Amount ) " & _
>> >> "SELECT " & lngInvID & " As NewInvoiceID,
>> >> tInvoiceDetail.Item, " & _
>> >> "tInvoiceDetail.Amount FROM tInvoiceDetail " & _
>> >> "WHERE (tInvoiceDetail.InvoiceID = " &
>> >> Me.InvoiceID &
>> >> ");"
>> >> db.Execute strSql, dbFailOnError
>> >> Else
>> >> MsgBox "Main record duplicated, but there were no
>> >> related
>> >> records."
>> >> End If
>> >>
>> >> 'Display the duplicate.
>> >> Me.Bookmark = .LastModified
>> >> End With
>> >> End If
>> >>
>> >> Set db = Nothing
>> >> End Sub
>> >>
>> >> "Barry" wrote in message
>> >> news:FD587861-DD2F-49D4-95E9-4CE4C0450729@microsoft.com...
>> >> >I have a form (formA) with a subform (formB) inside formA.
>> >> > I need to duplicate the record in formA which is not a problem but i
>> >> > also
>> >> > want to duplicate the current record in formB at the same time
>> >> > without
>> >> > having
>> >> > to place another duplicate button in this form.
>> >> >
>> >> > Can anyone help me with this?



Reply With Quote
  #9 (permalink)  
Old 09-Nov-2005, 17:51 PM
Barry's Avatar Barry
Guest
 
Posts: n/a
   
   
Re: Duplicate records in a subform

  Donate Today!  
I have got past this part of the code, I am using an SQL server to store the
data but now i receive an error " You must use dbSeeChanges option with
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
OpenRecordSet when accessing an SQL server table that has an identity column"

I have tried the following statement but i then get an error "Object required"
Set Duplicate = dbs.OpenRecordset(strSql, dbOpenDynaset, dbSeeChanges)

This gives duplicate a value of empty???
Can you help me...

"Allen Browne" wrote:

> NewId is just the alias for the number.
> You could call it anything at all.
> The statement should end up as:
> SELECT 789 AS YNotThisName, ...
>
> What matters is that the items in the SELECT clause match the same fields as
> those inside the brackets in the INSERT clause.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Barry" wrote in message
> news:0BF15F7F-C0C0-49E2-B349-D50A609E6A88@microsoft.com...
> >i am not sure what the "NewID" is in the statement
> > "SELECT " & lngID & " As NewID
> >
> > is this a function that is being called or should this be a field in the
> > table
> >
> >
> >
> > "Allen Browne" wrote:
> >
> >> The message indicates that you SQL string is not correct.
> >>
> >> Immediately above the dbEngine... line, add this line:
> >> Debug.Print strSQL
> >> Run the code.
> >> When if fails, open the Immediate Window (Ctrl+G).
> >> Can you see what's wrong with the statement? E.g.:
> >> - Spaces missing?
> >> - No value where you expected one?
> >> - Wrong field names?
> >> - Field or table names that contain spaces, that were not in square
> >> brackets?
> >>
> >> Mock up a dummy query to compare it to if that helps.
> >>
> >> "Barry" wrote in message
> >> news:448C0515-B211-49BF-9936-1FDF6935B247@microsoft.com...
> >> >I have a problem with this code
> >> >
> >> > it stops at the line DBEngine(0)(0).Execute strSql, dbFailOnError and
> >> > gives
> >> > an
> >> > error message "Syntax error in INSERT INTO statement"
> >> >
> >> > dbFailOnError has a value of 128 if this helps
> >> >
> >> >
> >> >
> >> > "Allen Browne" wrote:
> >> >
> >> >> The example below duplicates the invoice record in the main form and
> >> >> the
> >> >> line items from the subform.
> >> >>
> >> >> It illustrates 2 techniques:
> >> >> - The main record is duplciated in the form's RecordsetClone (using
> >> >> DAO).
> >> >> This gives you to new primary key value, which you need for the
> >> >> related
> >> >> records.
> >> >>
> >> >> - The child records are duplicated by executing an append query
> >> >> statement.
> >> >> This creates them all in one pass.
> >> >>
> >> >> The code then displays the newly created duplicate.
> >> >>
> >> >> Private Sub cmdDupe_Click()
> >> >> Dim strSql As String
> >> >> Dim db As DAO.Database
> >> >> Dim lngInvID As Long
> >> >>
> >> >> Set db = DBEngine(0)(0)
> >> >>
> >> >> If Me.Dirty Then 'Save first.
> >> >> Me.Dirty = False
> >> >> End If
> >> >> If Me.NewRecord Then
> >> >> MsgBox "Select the record to duplicate."
> >> >> Else
> >> >>
> >> >> 'Duplicate the main record
> >> >> With Me.RecordsetClone
> >> >> .AddNew
> >> >> !InvoiceDate = Date
> >> >> !ClientID = Me.ClientID
> >> >> 'etc for other fields.
> >> >> .Update
> >> >> .Bookmark = .LastModified
> >> >> lngInvID = !InvoiceID
> >> >>
> >> >> 'Duplicate the related records.
> >> >> If Me.fInvoiceDetail.Form.RecordsetClone.RecordCount > 0
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=6856
> >> >> Then
> >> >> strSql = "INSERT INTO tInvoiceDetail ( InvoiceID,
> >> >> Item,
> >> >> Amount ) " & _
> >> >> "SELECT " & lngInvID & " As NewInvoiceID,
> >> >> tInvoiceDetail.Item, " & _
> >> >> "tInvoiceDetail.Amount FROM tInvoiceDetail " & _
> >> >> "WHERE (tInvoiceDetail.InvoiceID = " &
> >> >> Me.InvoiceID &
> >> >> ");"
> >> >> db.Execute strSql, dbFailOnError
> >> >> Else
> >> >> MsgBox "Main record duplicated, but there were no
> >> >> related
> >> >> records."
> >> >> End If
> >> >>
> >> >> 'Display the duplicate.
> >> >> Me.Bookmark = .LastModified
> >> >> End With
> >> >> End If
> >> >>
> >> >> Set db = Nothing
> >> >> End Sub
> >> >>
> >> >> "Barry" wrote in message
> >> >> news:FD587861-DD2F-49D4-95E9-4CE4C0450729@microsoft.com...
> >> >> >I have a form (formA) with a subform (formB) inside formA.
> >> >> > I need to duplicate the record in formA which is not a problem but i
> >> >> > also
> >> >> > want to duplicate the current record in formB at the same time
> >> >> > without
> >> >> > having
> >> >> > to place another duplicate button in this form.
> >> >> >
> >> >> > Can anyone help me with this?

>
>
>

Reply With Quote
   Click Here to Donate Now!

Support Us!
Become a Promoter!
Gurfateh ji, you can become a SPN Promoter by Donating as little as $10 each month. With limited resources & high operational costs, your donations make it possible for us to deliver a quality website and spread the teachings of the Sri Guru Granth Sahib Ji, to serve & uplift humanity. Every contribution counts. Donate Generously. Gurfateh!
ReplyPost New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!

Bookmarks


(View-All Members who have read this thread : 0
There are no names to display.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Tools Search
Search:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

» Active Discussions
Woolwich Killing: The...
Today 14:01 PM
16 Replies, 189 Views
Paneer: what I have...
By Ishna
Today 13:48 PM
0 Replies, 4 Views
How does Sikhi help you...
Today 13:37 PM
45 Replies, 1,148 Views
Rochester Gurdwara...
Today 10:55 AM
2 Replies, 64 Views
Is Science a Religion?
Today 09:53 AM
11 Replies, 1,962 Views
US Congress panel passes...
Today 04:22 AM
0 Replies, 37 Views
Harmeet Kaur Took the...
Today 03:40 AM
0 Replies, 53 Views
Rozana Reports (ਪੰਜਾਬੀ...
Today 01:43 AM
319 Replies, 7,695 Views
Sikh Spokesman (ਪੰਜਾਬੀ...
Today 00:36 AM
182 Replies, 4,614 Views
Panjabi Alphabet Resource
Yesterday 23:15 PM
12 Replies, 6,558 Views
Transgenderism ... Right...
Yesterday 22:55 PM
30 Replies, 1,368 Views
Biography of a Scholar:...
Yesterday 22:53 PM
1 Replies, 74 Views
Dusting The Web
Yesterday 22:25 PM
0 Replies, 44 Views
How Pure the Tongue? New...
Yesterday 21:29 PM
0 Replies, 60 Views
Stockholm riots throw...
Yesterday 21:14 PM
1 Replies, 44 Views
» Books You Should Read...
Powered by vBadvanced CMPS v3.2.3
All times are GMT +6.5. The time now is 14:20 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2 Copyright © 2004-12, All Rights Reserved. Sikh Philosophy Network


Page generated in 0.87019 seconds with 32 queries
0