A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Duplicating reocords from main form and subform



 
 
Thread Tools Display Modes
  #21  
Old April 21st, 2009, 08:49 PM posted to microsoft.public.access.forms
rarerock via AccessMonster.com
external usenet poster
 
Posts: 10
Default Duplicating reocords from main form and subform

Think i fixed that, now i'm getting this error: Microsoft Access can't find
the field "I" referred to in your expression

John W. Vinson wrote:
In the statement - WHERE TripID = " & Me.TripID & ";"
Method or Data Member Not Found


That suggests that there is in fact nothing on the current Form (Me.) named
TripID.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200904/1

  #22  
Old April 22nd, 2009, 12:27 AM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Duplicating reocords from main form and subform

On Tue, 21 Apr 2009 19:49:40 GMT, "rarerock via AccessMonster.com"
u51057@uwe wrote:

Think i fixed that, now i'm getting this error: Microsoft Access can't find
the field "I" referred to in your expression


In that case you're trying to write to, or read from, a field named "I" and
that there is no such field.

Check your code and be sure your variables contain what you think they do.
--

John W. Vinson [MVP]
  #23  
Old April 23rd, 2009, 08:07 PM posted to microsoft.public.access.forms
rarerock via AccessMonster.com
external usenet poster
 
Posts: 10
Default Duplicating reocords from main form and subform

heres the code now. No errors, but the newly created record is blank??

Private Sub Duplicate_Click()
On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the
subform.
Dim strSql As String 'SQL statement.
Dim lngID As Long 'Primary key value of the new record.
'Save and edits first
If Me.Dirty Then
Me.Dirty = False
End If
'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.recordsetclone
.AddNew
!FNAME = Me.FNAME
!LNAME = Me.LNAME
!PHONE = Me.PHONE
!DCODE = Me.DCODE
!TYDATE = Me.TYDATE
!TPDATE = Me.TPDATE
!PLOCATION = Me.PLOCATION
!PTIME = Me.PTIME
!ATIME = Me.ATIME
!DLOCATION = Me.DLOCATION
!RLOCATION = Me.RLOCATION
!LTIME = Me.LTIME
!RTIME = Me.RTIME
!STAFF = Me.STAFF
!COMMENTS = Me.COMMENTS
'etc for other fields.
.Update
'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = !TRIPN
'Duplicate the related records: append query.
If Me.[Rider].Form.recordsetclone.RecordCount 0 Then
strSql = "INSERT INTO [Triders](TRIPN,NameID,TypeID)" & _
"SELECT " & lngID & " As NewID,NameID,TypeID " & _
"FROM [triders] WHERE (TRIPN = " & Me.TRIPN & ");"
DBEngine(0)(0).Execute strSql, dbFailOnError
Else
MsgBox "Main record duplicated, but there were no related
records."
End If
'Display the new duplicate.
Me.Bookmark = .LastModified
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"Duplicate_Click"
Resume Exit_Handler
End Sub

John W. Vinson wrote:
Think i fixed that, now i'm getting this error: Microsoft Access can't find
the field "I" referred to in your expression


In that case you're trying to write to, or read from, a field named "I" and
that there is no such field.

Check your code and be sure your variables contain what you think they do.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200904/1

  #24  
Old April 29th, 2009, 05:23 PM posted to microsoft.public.access.forms
rarerock via AccessMonster.com
external usenet poster
 
Posts: 10
Default Duplicating reocords from main form and subform

Not sure if you saw my last post. I'm still playing with this code, when i
duplicate the record it is blank, i even removed the sql statement to see if
that was the problem, only the PK and the FK number advances in either case?
Any idea why?

John W. Vinson wrote:
Think i fixed that, now i'm getting this error: Microsoft Access can't find
the field "I" referred to in your expression


In that case you're trying to write to, or read from, a field named "I" and
that there is no such field.

Check your code and be sure your variables contain what you think they do.


--
Message posted via http://www.accessmonster.com

 




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:02 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.