SetFocus code not working

lmcc007

Registered User.
Local time
Today, 16:51
Joined
Nov 10, 2007
Messages
635
I am trying to say that if cboSource or cboWorkType is null, display a message and then go back to the field on the form that is null. Problem is, the form closes displaying the message. Below is what it is doing:

1. I hit OK button to close form
2. Message box displays saying cboSource is null.
3. I hit OK to close the Message box
4. Form closes​

Below is the code I am using:

Code:
Private Sub Form_AfterUpdate()

    If IsNull(Me!cboSource) Then
        MsgBox ("The ""Source"" must be entered."), vbCritical, gstrAppTitle
        Me!cboSource.SetFocus
    ElseIf IsNull(Me!cboWorkType) Then
        MsgBox ("The ""Work Type"" must be entered."), vbCritical, gstrAppTitle
        Me!cboWorkType.SetFocus
    Else
        DoCmd.Close acForm, "fdlgContractDetail", acSavePrompt   ' User wants to save and close the form
    End If
    
End Sub


Private Sub cmdOK_Click()

On Error GoTo ErrorHandler

    DoCmd.Close acForm, "fdlgJobDetail", acSavePrompt   ' User wants to save and close the form
    
    
CleanUpAndExit:
    Exit Sub

ErrorHandler:
    Call MsgBox("An error was encountered" & vbCrLf & vbCrLf & _
        "Description:  " & Err.Description & vbCrLf & _
        "Error Number:  " & Err.Number, vbCritical, gstrAppTitle)
    Resume CleanUpAndExit

End Sub
 
Happy to help!
Okay, I'm looking at your website on OpenArg. Is OpenArg a technical term of MS? I'm not getting it. Is it like saying "Open Form1 and put Renee in FirstName field?
 
Yes, OpenArgs is an argument available for OpenForm and OpenReport (depending on version) that let's you pass a value to the form/report being opened. You can access that value as long as the form/report is open.
 
Yes, OpenArgs is an argument available for OpenForm and OpenReport (depending on version) that let's you pass a value to the form/report being opened. You can access that value as long as the form/report is open.

So, if I close Form2 the value is no longer available. Meaning, if I choose an item from a combo box and I tell the Pop up which is Form2 on closing to do: Forms!Form1!txtDesc = Forms!Form2!combo1.column(1) that when closing the forms that information put into txtDesc will be lost.
 

Users who are viewing this thread

Back
Top Bottom