Hello everyone.
I desperately need help with this project, and I will appreciate any suggestions.
I have a Main form with a subform, which in turn has another subform with a tab control with other three forms in each tab. Each form corresponds to a separate table each. I set up this form to add a new record for all the forms, add a new record for an existing record of the main form, and to edit records in all the forms. I use three command buttons to perform these procedures using the following code, which works fine for editing and adding a record for an existing main record, but when I tried to add an entire new record it fails and closes the application with no error messages.
Public Sub subFormMode(strTag As String)
On Error GoTo subFormMode_Err
'Set the editing mode of the form based on the supplied string
Select Case strTag
Case Is = "Add"
Forms![MainSWInitialEncounter]![Enrollment].Form![SWInitialEncounter].Form!Page1.SetFocus
Me.ClientID.SetFocus
'Set edit permissions
Me.AllowAdditions = True
Me.Enrollment.Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowAdditions = True
Me.AllowEdits = True
Me.Enrollment.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowEdits = True
'Set form tag
Me.Tag = "Add"
'Change command buttons
Me.CmdAddRecord.Enabled = False
Me.CmdAddRecord.Caption = "Add Record to Existing Client"
Me.CmdAddNewRecord.Enabled = True
Me.CmdAddNewRecord.Caption = "Save Record"
Me.CmdEdit.Caption = "Edit Record"
Me.CmdEdit.Enabled = False
'Set record position
DoCmd.GoToRecord acDataForm, "MainSWInitialEncounter", acNewRec
Case Is = "Edit"
Forms![MainSWInitialEncounter]![Enrollment].Form![SWInitialEncounter].Form!Page1.SetFocus
Me.ClientID.SetFocus
'Set edit permissions
Me.AllowAdditions = False
Me.Enrollment.Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowAdditions = False
Me.AllowEdits = True
Me.Enrollment.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowEdits = True
'Set form tag
Me.Tag = "Edit"
'Change command buttons
Me.CmdAddRecord.Enabled = False
Me.CmdAddRecord.Caption = "Add Record to Existing Client"
Me.CmdAddNewRecord.Enabled = False
Me.CmdAddNewRecord.Caption = "Add New Client"
Me.CmdEdit.Caption = "Done / Save"
Me.CmdEdit.Enabled = True
Case Is = "Read"
Forms![MainSWInitialEncounter]![Enrollment].Form![SWInitialEncounter].Form!Page1.SetFocus
Me.ClientID.SetFocus
'Set record position
intEmpCount = Nz(DCount("[Clients]![ClientID]", "Clients"), 0)
If intEmpCount > 0 Then
DoCmd.FindRecord intEmpCount, acEntire, , acSearchAll, , acCurrent
If Me.CmdAddNewRecord.Enabled = True Then
DoCmd.GoToControl "CmdAddNewRecord"
Else
DoCmd.GoToControl "CmdAddRecord"
End If
End If
'Set edit permissions
Me.AllowAdditions = False
Me.Enrollment.Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowAdditions = False
Me.AllowEdits = False
Me.Enrollment.Form.AllowEdits = False
Me.Enrollment.Form!SWInitialEncounter.Form.AllowEdits = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowEdits = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowEdits = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowEdits = False
'Change command buttons
Me.CmdAddRecord.Enabled = True
Me.CmdAddRecord.Caption = "Add Record to Existing Client"
Me.CmdAddNewRecord.Enabled = True
Me.CmdAddNewRecord.Caption = "Add New Client"
Me.CmdEdit.Caption = "Edit Record"
Me.CmdEdit.Enabled = True
'Set form tag
Me.Tag = "Read"
Case Else
Exit Sub
End Select
Exit Sub
subFormMode_Err:
MsgBox Err.Number & " - " & Err.Description
End Sub
This is the code to add a record for an existing Client of the main form. This also works fine.
Public Sub subModeRead(strTag As String)
On Error GoTo subModeRead_Err
'Set the editing mode of the form based on the supplied string
Select Case strTag
Case Is = "Add"
Forms![MainSWInitialEncounter]![Enrollment].Form![SWInitialEncounter].Form!Page1.SetFocus
Me.Enrollment.SetFocus
'Set edit permissions
Me.AllowAdditions = False
Me.Enrollment.Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowAdditions = True
Me.AllowEdits = True
Me.Enrollment.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowEdits = True
'Set form tag
Me.Tag = "Add"
'Change command buttons
Me.CmdAddRecord.Enabled = True
Me.CmdAddRecord.Caption = "Save Record"
Me.CmdAddNewRecord.Enabled = False
Me.CmdAddNewRecord.Caption = "Add New Client"
Me.CmdEdit.Caption = "Edit Record"
Me.CmdEdit.Enabled = False
DoCmd.RunCommand acCmdRecordsGoToNew
Me.Enrollment!EnrollmentNumber.SetFocus
Case Else
Exit Sub
End Select
Exit Sub
subModeRead_Err:
MsgBox Err.Number & " - " & Err.Description
End Sub
Could anybody please tell me what is wrong here?
Thanks
I desperately need help with this project, and I will appreciate any suggestions.
I have a Main form with a subform, which in turn has another subform with a tab control with other three forms in each tab. Each form corresponds to a separate table each. I set up this form to add a new record for all the forms, add a new record for an existing record of the main form, and to edit records in all the forms. I use three command buttons to perform these procedures using the following code, which works fine for editing and adding a record for an existing main record, but when I tried to add an entire new record it fails and closes the application with no error messages.
Public Sub subFormMode(strTag As String)
On Error GoTo subFormMode_Err
'Set the editing mode of the form based on the supplied string
Select Case strTag
Case Is = "Add"
Forms![MainSWInitialEncounter]![Enrollment].Form![SWInitialEncounter].Form!Page1.SetFocus
Me.ClientID.SetFocus
'Set edit permissions
Me.AllowAdditions = True
Me.Enrollment.Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowAdditions = True
Me.AllowEdits = True
Me.Enrollment.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowEdits = True
'Set form tag
Me.Tag = "Add"
'Change command buttons
Me.CmdAddRecord.Enabled = False
Me.CmdAddRecord.Caption = "Add Record to Existing Client"
Me.CmdAddNewRecord.Enabled = True
Me.CmdAddNewRecord.Caption = "Save Record"
Me.CmdEdit.Caption = "Edit Record"
Me.CmdEdit.Enabled = False
'Set record position
DoCmd.GoToRecord acDataForm, "MainSWInitialEncounter", acNewRec
Case Is = "Edit"
Forms![MainSWInitialEncounter]![Enrollment].Form![SWInitialEncounter].Form!Page1.SetFocus
Me.ClientID.SetFocus
'Set edit permissions
Me.AllowAdditions = False
Me.Enrollment.Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowAdditions = False
Me.AllowEdits = True
Me.Enrollment.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowEdits = True
'Set form tag
Me.Tag = "Edit"
'Change command buttons
Me.CmdAddRecord.Enabled = False
Me.CmdAddRecord.Caption = "Add Record to Existing Client"
Me.CmdAddNewRecord.Enabled = False
Me.CmdAddNewRecord.Caption = "Add New Client"
Me.CmdEdit.Caption = "Done / Save"
Me.CmdEdit.Enabled = True
Case Is = "Read"
Forms![MainSWInitialEncounter]![Enrollment].Form![SWInitialEncounter].Form!Page1.SetFocus
Me.ClientID.SetFocus
'Set record position
intEmpCount = Nz(DCount("[Clients]![ClientID]", "Clients"), 0)
If intEmpCount > 0 Then
DoCmd.FindRecord intEmpCount, acEntire, , acSearchAll, , acCurrent
If Me.CmdAddNewRecord.Enabled = True Then
DoCmd.GoToControl "CmdAddNewRecord"
Else
DoCmd.GoToControl "CmdAddRecord"
End If
End If
'Set edit permissions
Me.AllowAdditions = False
Me.Enrollment.Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowAdditions = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowAdditions = False
Me.AllowEdits = False
Me.Enrollment.Form.AllowEdits = False
Me.Enrollment.Form!SWInitialEncounter.Form.AllowEdits = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowEdits = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowEdits = False
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowEdits = False
'Change command buttons
Me.CmdAddRecord.Enabled = True
Me.CmdAddRecord.Caption = "Add Record to Existing Client"
Me.CmdAddNewRecord.Enabled = True
Me.CmdAddNewRecord.Caption = "Add New Client"
Me.CmdEdit.Caption = "Edit Record"
Me.CmdEdit.Enabled = True
'Set form tag
Me.Tag = "Read"
Case Else
Exit Sub
End Select
Exit Sub
subFormMode_Err:
MsgBox Err.Number & " - " & Err.Description
End Sub
This is the code to add a record for an existing Client of the main form. This also works fine.
Public Sub subModeRead(strTag As String)
On Error GoTo subModeRead_Err
'Set the editing mode of the form based on the supplied string
Select Case strTag
Case Is = "Add"
Forms![MainSWInitialEncounter]![Enrollment].Form![SWInitialEncounter].Form!Page1.SetFocus
Me.Enrollment.SetFocus
'Set edit permissions
Me.AllowAdditions = False
Me.Enrollment.Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowAdditions = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowAdditions = True
Me.AllowEdits = True
Me.Enrollment.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWRiskAssessment].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWHealthEducation].Form.AllowEdits = True
Me.Enrollment.Form!SWInitialEncounter.Form![SWIssuesNeeds].Form.AllowEdits = True
'Set form tag
Me.Tag = "Add"
'Change command buttons
Me.CmdAddRecord.Enabled = True
Me.CmdAddRecord.Caption = "Save Record"
Me.CmdAddNewRecord.Enabled = False
Me.CmdAddNewRecord.Caption = "Add New Client"
Me.CmdEdit.Caption = "Edit Record"
Me.CmdEdit.Enabled = False
DoCmd.RunCommand acCmdRecordsGoToNew
Me.Enrollment!EnrollmentNumber.SetFocus
Case Else
Exit Sub
End Select
Exit Sub
subModeRead_Err:
MsgBox Err.Number & " - " & Err.Description
End Sub
Could anybody please tell me what is wrong here?
Thanks