Duplicating reocords from main form and subform

R

rarerock via AccessMonster.com

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

John W. Vinson

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.
 
R

rarerock via AccessMonster.com

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
 
R

rarerock via AccessMonster.com

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top