gakiss2
Registered User.
- Local time
- Yesterday, 20:40
- Joined
- Nov 21, 2018
- Messages
- 168
I have a form which contains a combo box named DocType. In usual operation it works fine. user selects from a list coming off a table. real simple, must be from list.
I added a button on my 'Front Page' form called NewSwitchboard . I want the button to launch the above form in Add mode and to prepopulate DocType with a specific one of the choices, that is, "Deviation Authorization". In normal use there are no issues with the user selecting "Deviation Authorization", works like a charm. There is more automation that I want to do after I get past this roadblock but most of that is unrelated to this topic. Here is the code that I have to launch the form in addmode, you'll see I added an OpenArg.
And I added an Form_Open procedure to the form that gets opened above, frmDocDetail.
I've gotten so far that I can have the opened form spit the OpenArg back to me in a Msgbox but I'm having trouble getting it to populate the DocType combo box with "Deviation Authorization". I'm not really sure I need OpenArgs since I want this button to always prepopulate with "Dev..." It was a suggestion from something I found on line. I Don't want it prepopulated with "Dev.." every time this form gets opened in add mode though, just when it gets opened form my new button. Also I have a button that just opens a new form (same form in add mode) and it works fine. There is code to make sure the user selects the DocType first by locking all other records after Form_Activate event and stays locked until 'After_Update' for DocType. I think this should be OK since I am trying to populate DocType first and I don't really know if locking a field / control even prevents code from manipulating it. the database it attached if you need to look there. the locking and unlocking occurs just below the Form_Open procedure on the frmDocDetail code.
I added a button on my 'Front Page' form called NewSwitchboard . I want the button to launch the above form in Add mode and to prepopulate DocType with a specific one of the choices, that is, "Deviation Authorization". In normal use there are no issues with the user selecting "Deviation Authorization", works like a charm. There is more automation that I want to do after I get past this roadblock but most of that is unrelated to this topic. Here is the code that I have to launch the form in addmode, you'll see I added an OpenArg.
Code:
Private Sub cmdDev_Click()
DoCmd.Close acForm, "NewSwitchboard", acSaveNo
DoCmd.OpenForm "frmDocDetail", acNormal, , , acFormAdd, , "Deviation Authorization"
End Sub
And I added an Form_Open procedure to the form that gets opened above, frmDocDetail.
Code:
Private Sub Form_Open(Cancel As Integer)
Dim initDocType As String
' MsgBox "open args" & Forms!frmDocDetail.OpenArgs
initDocType = Forms!frmDocDetail.OpenArgs
If Len(initDocType) > 0 Then
MsgBox "OK, now what"
Me.DocType.Column(1) = initDocType
End If
End Sub
I've gotten so far that I can have the opened form spit the OpenArg back to me in a Msgbox but I'm having trouble getting it to populate the DocType combo box with "Deviation Authorization". I'm not really sure I need OpenArgs since I want this button to always prepopulate with "Dev..." It was a suggestion from something I found on line. I Don't want it prepopulated with "Dev.." every time this form gets opened in add mode though, just when it gets opened form my new button. Also I have a button that just opens a new form (same form in add mode) and it works fine. There is code to make sure the user selects the DocType first by locking all other records after Form_Activate event and stays locked until 'After_Update' for DocType. I think this should be OK since I am trying to populate DocType first and I don't really know if locking a field / control even prevents code from manipulating it. the database it attached if you need to look there. the locking and unlocking occurs just below the Form_Open procedure on the frmDocDetail code.