Better way to Call/Open Forms Code

Dwaynair

New member
Local time
Today, 21:15
Joined
Jan 11, 2000
Messages
6
Bellow is the code I use to open one of a possible 20 Forms based on the selected record in the current form.
But there has to be a better way so that I do not have to code every new form I will create.

Function ModifyOpen()
'
'This will Open selected record and Modify if its from the open tour.
'******************************************************************************************

Dim strMsg As String
strMsg = "This will Modify your Record!"
Beep
If MsgBox(strMsg, vbOKCancel) = vbOK Then

Dim db As Database
Set db = CurrentDb()

With CodeContextObject
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm

If (frmCurrentForm.subject_form = "Property") Then
' Open the property form and show current record selected.
DoCmd.OpenForm "Property", acNormal, "", "[PropertyDamage]![id_numb]=[Forms]![ASOPMainPage]![id]", acEdit, acNormal
DoCmd.RunCommand acCmdDocRestore
End If

If (frmCurrentForm.subject_form = "Bodily") Then
DoCmd.OpenForm "Bodily", acNormal, "", "[BodilyInjury]![id_numb]=[Forms]![ASOPMainPage]![id]", acEdit, acNormal

DoCmd.RunCommand acCmdDocRestore
End If

If (frmCurrentForm.subject_form = "Acincident_frm") Then
DoCmd.OpenForm "Acincident_frm", acNormal, "", [ac_incident]![id_numb]=[Forms]![ASOPMainPage]![id]", acEdit, acNormal,
DoCmd.RunCommand acCmdDocRestore
End If

etc, etc

These are just two forms being used
Somewhat new to VB so thanks.
 

Users who are viewing this thread

Back
Top Bottom