Copy of record not copying all fields

J

jturn00

I am not sure why. Ok, I might have a slight clue as it might relate to the
code below.

I have a contact form ("Contact Form") that by clicking a button opens a
detail note form ("Detail Form"). These are related by having an id field on
the Contact Form that relates to the Detail Form in a field DetailID. This
works fine. But when I am on the Detail Form and want to create a new record
(and copy the information) and in particular, use the same DetailID. When I
used the default button, it copies the information EXCEPT the DetailID.

The DetailID is also not passed when I use the standard Access create new
record arrows at the bottom of the page.

I think it has to do with how I have code to open the Detail Form from the
contact form below. But I am not sure. Command108_Click() is the button in
the Detail form where I want the DetailID to pass to the newly created Detail
Form record. OpenForm_Click() is the code to open the detail form (And
create a new record from the customer record).

Jeff

Option Compare Database




Private Sub CreateNewIssue_Click()

End Sub

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.UserCreated = fOSUserName()
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.DateModified = Now()
Me.UserModified = fOSUserName()



'Provide the user with the option to save/undo
'changes made to the record in the form

If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then
DoCmd.Save
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub



Private Sub UndoSubpoena_Click()
On Error GoTo Err_UndoSubpoena_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_UndoSubpoena_Click:
Exit Sub

Err_UndoSubpoena_Click:
MsgBox Err.Description
Resume Exit_UndoSubpoena_Click

End Sub
Private Sub Form_Current()
Me!UndoSubpoena.Enabled = False

' With Me![Subpoena Comments Subform].Form
' .Visible = (.RecordsetClone.RecordCount > 0)
' End With


End Sub

Private Sub Form_Dirty(Cancel As Integer)
Me!UndoSubpoena.Enabled = True
End Sub

Private Sub OpenForm_Click()
On Error GoTo Err_OpenForm_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stTeststring As String
stTeststring = "Test from click on button"
stDocName = "Subpoena Comments"

'stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria


'DoCmd.GoToRecord acDataForm, stLinkCriteria, acNewRec
DoCmd.GoToRecord , , acNewRec
' DoCmd.RunCommand acCmdRecordsGoToNew
Me![Comment] = stTeststring
Me!UserCreated.Value = fOSUserName()
Me!UserModified.Value = fOSMachineName()
Me!DateCreated.Value = Now()
RunCommand acCmdSaveRecord


Exit_OpenForm_Click:
Exit Sub

Err_OpenForm_Click:
MsgBox Err.Description
Resume Exit_OpenForm_Click

End Sub

Private Sub Save_Subpoena_Detail_Click()
On Error GoTo Err_Save_Subpoena_Detail_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Save_Subpoena_Detail_Click:
Exit Sub

Err_Save_Subpoena_Detail_Click:
MsgBox Err.Description
Resume Exit_Save_Subpoena_Detail_Click

End Sub
Private Sub Command108_Click()
On Error GoTo Err_Command108_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

Exit_Command108_Click:
Exit Sub

Err_Command108_Click:
MsgBox Err.Description
Resume Exit_Command108_Click

End Sub
 
J

Jeff Boyce

It all starts with the data (not the forms)...

I'll hazard a guess that you have Contacts, and that each Contact can have
one or more Details/Notes. If that is the relationship of your data (i.e.,
your tables), you can use the main form/subform construction to
automatically add the primary key of the main form (table) to the subform
(table) when you add a new record in the subform. No need to pop open
another form!

Good luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP

jturn00 said:
I am not sure why. Ok, I might have a slight clue as it might relate to
the
code below.

I have a contact form ("Contact Form") that by clicking a button opens a
detail note form ("Detail Form"). These are related by having an id field
on
the Contact Form that relates to the Detail Form in a field DetailID.
This
works fine. But when I am on the Detail Form and want to create a new
record
(and copy the information) and in particular, use the same DetailID. When
I
used the default button, it copies the information EXCEPT the DetailID.

The DetailID is also not passed when I use the standard Access create new
record arrows at the bottom of the page.

I think it has to do with how I have code to open the Detail Form from the
contact form below. But I am not sure. Command108_Click() is the button
in
the Detail form where I want the DetailID to pass to the newly created
Detail
Form record. OpenForm_Click() is the code to open the detail form (And
create a new record from the customer record).

Jeff

Option Compare Database




Private Sub CreateNewIssue_Click()

End Sub

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.UserCreated = fOSUserName()
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.DateModified = Now()
Me.UserModified = fOSUserName()



'Provide the user with the option to save/undo
'changes made to the record in the form

If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then
DoCmd.Save
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub



Private Sub UndoSubpoena_Click()
On Error GoTo Err_UndoSubpoena_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_UndoSubpoena_Click:
Exit Sub

Err_UndoSubpoena_Click:
MsgBox Err.Description
Resume Exit_UndoSubpoena_Click

End Sub
Private Sub Form_Current()
Me!UndoSubpoena.Enabled = False

' With Me![Subpoena Comments Subform].Form
' .Visible = (.RecordsetClone.RecordCount > 0)
' End With


End Sub

Private Sub Form_Dirty(Cancel As Integer)
Me!UndoSubpoena.Enabled = True
End Sub

Private Sub OpenForm_Click()
On Error GoTo Err_OpenForm_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stTeststring As String
stTeststring = "Test from click on button"
stDocName = "Subpoena Comments"

'stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria


'DoCmd.GoToRecord acDataForm, stLinkCriteria, acNewRec
DoCmd.GoToRecord , , acNewRec
' DoCmd.RunCommand acCmdRecordsGoToNew
Me![Comment] = stTeststring
Me!UserCreated.Value = fOSUserName()
Me!UserModified.Value = fOSMachineName()
Me!DateCreated.Value = Now()
RunCommand acCmdSaveRecord


Exit_OpenForm_Click:
Exit Sub

Err_OpenForm_Click:
MsgBox Err.Description
Resume Exit_OpenForm_Click

End Sub

Private Sub Save_Subpoena_Detail_Click()
On Error GoTo Err_Save_Subpoena_Detail_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Save_Subpoena_Detail_Click:
Exit Sub

Err_Save_Subpoena_Detail_Click:
MsgBox Err.Description
Resume Exit_Save_Subpoena_Detail_Click

End Sub
Private Sub Command108_Click()
On Error GoTo Err_Command108_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

Exit_Command108_Click:
Exit Sub

Err_Command108_Click:
MsgBox Err.Description
Resume Exit_Command108_Click

End Sub
 
J

jturn00 via AccessMonster.com

Thanks Jeff,

I checked and that is how the table realtion is setup. Unfortunately, I am
not working with newly created forms but with a previously worked on Access
project. I am not entirely clear on how I don't need to open the subform (not
sure if it is specifically a subform, but I have a form that is linked to the
main form) to add a new record but I have a button that does just that from
the main form. It opens a detail page with the same id as the main form. I
can enter information and everything is working fine. BUT after I save and I
want to creat a new record or duplicate a record with the form I just opened,
it clears the id field that has the relationship to my main form.

Jeff

Jeff said:
It all starts with the data (not the forms)...

I'll hazard a guess that you have Contacts, and that each Contact can have
one or more Details/Notes. If that is the relationship of your data (i.e.,
your tables), you can use the main form/subform construction to
automatically add the primary key of the main form (table) to the subform
(table) when you add a new record in the subform. No need to pop open
another form!

Good luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP
I am not sure why. Ok, I might have a slight clue as it might relate to
the
[quoted text clipped - 134 lines]
 
J

Jeff Boyce

You might want to spend a bit more time reading up on main form/subform
construction. If you've used the built-in features Access provides, Access
handles adding a foreign key (i.e., the main form's primary key) to a
newly-entered subform record.

Regards

Jeff Boyce
Microsoft Office/Access MVP

jturn00 via AccessMonster.com said:
Thanks Jeff,

I checked and that is how the table realtion is setup. Unfortunately, I
am
not working with newly created forms but with a previously worked on
Access
project. I am not entirely clear on how I don't need to open the subform
(not
sure if it is specifically a subform, but I have a form that is linked to
the
main form) to add a new record but I have a button that does just that
from
the main form. It opens a detail page with the same id as the main form.
I
can enter information and everything is working fine. BUT after I save
and I
want to creat a new record or duplicate a record with the form I just
opened,
it clears the id field that has the relationship to my main form.

Jeff

Jeff said:
It all starts with the data (not the forms)...

I'll hazard a guess that you have Contacts, and that each Contact can have
one or more Details/Notes. If that is the relationship of your data
(i.e.,
your tables), you can use the main form/subform construction to
automatically add the primary key of the main form (table) to the subform
(table) when you add a new record in the subform. No need to pop open
another form!

Good luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP
I am not sure why. Ok, I might have a slight clue as it might relate to
the
[quoted text clipped - 134 lines]
 
J

jturn00 via AccessMonster.com

Thanks! I will have to do that. I think I got it working and or at least
have a workable workaround.

Thanks again,

Jeff
Jeff said:
You might want to spend a bit more time reading up on main form/subform
construction. If you've used the built-in features Access provides, Access
handles adding a foreign key (i.e., the main form's primary key) to a
newly-entered subform record.

Regards

Jeff Boyce
Microsoft Office/Access MVP
Thanks Jeff,
[quoted text clipped - 40 lines]
 

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