A
Amy McElroy
I'm trying having trouble programming an Add Record button
to insert a record on a subform.
The subform Purchase_History_Form is on a tab control on
the main form, Contact_Info_Form.
I got the Edit Record and Save Record buttons to work, but
the Add Record button brings up the message: "The
object 'Purchase_History_Form' isn't open."
Can anyone point out my error? The code on the subform is
below.
Thank you!
- Amy
Option Compare Database
Option Explicit
Private Sub MakeFormReadOnly()
Me.AllowEdits = False
Me.BTNEditRecord.Enabled = True
Me.BTNSaveRecord.Enabled = False
End Sub
Private Sub BTN_Add_Record_Click()
On Error GoTo Err_BTN_Add_Record_Click
Me.AllowAdditions = True
DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
Me.ContactID.SetFocus
Me.BTNEditRecord.Enabled = False
Me.BTNSaveRecord.Enabled = True
Exit_BTN_Add_Record_Click:
Exit Sub
Err_BTN_Add_Record_Click:
MsgBox Err.Description
Resume Exit_BTN_Add_Record_Click
End Sub
Private Sub BTNEditRecord_Click()
Me.AllowEdits = True 'Allow Record to be edited
Me.SerialNumber.SetFocus
Me.BTNEditRecord.Enabled = False
Me.BTNSaveRecord.Enabled = True
End Sub
Private Sub Form_AfterUpdate()
MakeFormReadOnly 'Prevent Record from being
edited
End Sub
Private Sub Form_Current()
MakeFormReadOnly 'Prevent Record from being
edited
End Sub
Private Sub BTNSaveRecord_Click()
On Error GoTo Err_BTNSaveRecord_Click
Me.SerialNumber.SetFocus
DoCmd.DoMenuItem acFormBar, acRecordsMenu,
acSaveRecord, , acMenuVer70
MakeFormReadOnly 'Prevent Record from being
edited
Exit_BTNSaveRecord_Click:
Exit Sub
Err_BTNSaveRecord_Click:
MsgBox Err.Description
Resume Exit_BTNSaveRecord_Click
End Sub
to insert a record on a subform.
The subform Purchase_History_Form is on a tab control on
the main form, Contact_Info_Form.
I got the Edit Record and Save Record buttons to work, but
the Add Record button brings up the message: "The
object 'Purchase_History_Form' isn't open."
Can anyone point out my error? The code on the subform is
below.
Thank you!
- Amy
Option Compare Database
Option Explicit
Private Sub MakeFormReadOnly()
Me.AllowEdits = False
Me.BTNEditRecord.Enabled = True
Me.BTNSaveRecord.Enabled = False
End Sub
Private Sub BTN_Add_Record_Click()
On Error GoTo Err_BTN_Add_Record_Click
Me.AllowAdditions = True
DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
Me.ContactID.SetFocus
Me.BTNEditRecord.Enabled = False
Me.BTNSaveRecord.Enabled = True
Exit_BTN_Add_Record_Click:
Exit Sub
Err_BTN_Add_Record_Click:
MsgBox Err.Description
Resume Exit_BTN_Add_Record_Click
End Sub
Private Sub BTNEditRecord_Click()
Me.AllowEdits = True 'Allow Record to be edited
Me.SerialNumber.SetFocus
Me.BTNEditRecord.Enabled = False
Me.BTNSaveRecord.Enabled = True
End Sub
Private Sub Form_AfterUpdate()
MakeFormReadOnly 'Prevent Record from being
edited
End Sub
Private Sub Form_Current()
MakeFormReadOnly 'Prevent Record from being
edited
End Sub
Private Sub BTNSaveRecord_Click()
On Error GoTo Err_BTNSaveRecord_Click
Me.SerialNumber.SetFocus
DoCmd.DoMenuItem acFormBar, acRecordsMenu,
acSaveRecord, , acMenuVer70
MakeFormReadOnly 'Prevent Record from being
edited
Exit_BTNSaveRecord_Click:
Exit Sub
Err_BTNSaveRecord_Click:
MsgBox Err.Description
Resume Exit_BTNSaveRecord_Click
End Sub