Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Repeat On Not in List event for multiple forms

$
0
0
Hello,

I have code in a form named "frmFootball" in the On not in list event that allows me to add a new customer if a customer is not listed in a combobox named "customer".

What it does is asks me if I want to add a new customer, I click Yes, then a customer form ("frmCustomers") pops up and I enter the customer info. When I click close, I return back to my football form and that new customer is already entered in the customer field.

Everything works great. However, I want to know if there's a way to let this work on other forms. I have 2 more forms named
"frmBasketball" and "frmSoccer" that have different information and can't be combined into one form.

Is it possible to modify the if statement to work with all 3 forms? Only 1 form could be opened at a time.



Code:

Private Sub Command15_Click()
On Error GoTo errline

Const conObjStateClosed = 0
Const ConDesignView = 0
Dim IsFormLoaded As Boolean
DoCmd****nCommand acCmdSaveRecord

'Check if the original data entry form with the list is open
If SysCmd(acSysCmdGetObjectState, acForm, "frmFootball") <> conObjStateClosed Then
    If Forms("frmFootball").CurrentView <> ConDesignView Then
        IsFormLoaded = True
    End If
End If


If IsFormLoaded = True Then 'Check if the original data entry form with the list is open
    If Forms![frmFootball]![txtHiddenField] = "Addok" Then 'Checks if flag is active
      Forms![frmFootball]![Customer].Requery 'Refresh the list
      Forms![frmFootball]![Customer] = Me.CustRecID 'Set the List control
      Forms![frmFootball]![txtHiddenField] = "AddDone" 'Turn off the Not in list Flag
      DoCmd.Close acForm, "frmCustomers" 'Close the current lookup maintenance for the customers form
      Forms![frmFootball].SetFocus
      Forms![frmFootball]![Customer].SetFocus
    Else
        DoCmd.Close acForm, "frmCustomers"
    End If
Else
    DoCmd.Close acForm, "frmCustomers"
End If
exitline:
Exit Sub
errline:
Select Case Err.Number
Case 2501
End Select
End Sub

Thanks in advance!

Viewing all articles
Browse latest Browse all 13329

Trending Articles