Hi there
I have a little difficulty with my codes When I want to close my form called “sales”.
I have following codes in it’s UnLoad event, and it checks for the value of 2 txtboxes before it closes, And it works;
Private Sub Form_Unload(Cancel As Integer)
If Sd.Value - SC.Value <> 0 Then
MsgBox "Entries are Out of Balance", vbOKOnly, "Inventory 101"
DoCmd.CancelEvent
End If
End Sub
But here is the challenge, There are 2 controls on this form “combo144” (tab Indexed 0), and “InvoiceID100” (Tab Indexed 2), that are sort of important, and neither of them should have a value Null, when the user wants to close this form.
How would you do this?
At present I tried it with codes in LostFocus events of the bove controls, which should take care of this issue for me, But they do not work all the times, Here are those codes;
Private Sub InvoiceID100_LostFocus()
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
If IsNull(Me.InvoiceID100) Or Me.InvoiceID100 = "" Then
strMsg = "You must Enter an Invoice No. A Date Or Check No.."
strTitle = "Invoice Number Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Me.ReffrenceID.SetFocus
Me.InvoiceID100.SetFocus
Cancel = True
End If
End Sub
Private Sub Combo144_LostFocus()
Dim strMsg As String
Dim strTitle As String
Dim intStyle As Integer
Dim MyResp As Integer
If (IsNull(Me!Combo144)) Then
strMsg = "You must select a Customer!"
strMsg = strMsg & vbCrLf & "If you want to choose it from the ComboList, press Yes."
strMsg = strMsg & vbCrLf & "Other wise Press No, And Just Enter it"
strMsg = strMsg & vbCrLf & "In Order to close the Form Press Cancel"
strTitle = "Bill To Customer Required"
intStyle = vbYesNoCancel + vbQuestion
MyResp = MsgBox(strMsg, intStyle, strTitle)
If (MyResp = vbNo) Then
Me.Combo144.Value = "Guest"
Me.InvoiceID100.SetFocus
ElseIf (MyResp = vbYes) Then
Me.CompanyName.SetFocus
Me.Combo144.SetFocus
ElseIf (MyResp = vbCancel) Then
DoCmd.Close acForm, "Sales", acSaveNo
End If
End If
End Sub
There are 2 problems with these codes;
1. When the Combo144 is not Null, But InvoiceId100 is null and the user decides to close this forms. The InvoiceId100 msgBox Pops Up for 3 times, But the form closes after the third one, Well the user should not be able to close at all.
2. Also In my combo144 , when the user gets the Bove MsgBox and chooses to push the Cancel Button (The button that should close the form), the form does not closes and the curser gets focused on to next Control.
What are the problems with the above codes?
Best Regards
Sanan
I have a little difficulty with my codes When I want to close my form called “sales”.
I have following codes in it’s UnLoad event, and it checks for the value of 2 txtboxes before it closes, And it works;
Private Sub Form_Unload(Cancel As Integer)
If Sd.Value - SC.Value <> 0 Then
MsgBox "Entries are Out of Balance", vbOKOnly, "Inventory 101"
DoCmd.CancelEvent
End If
End Sub
But here is the challenge, There are 2 controls on this form “combo144” (tab Indexed 0), and “InvoiceID100” (Tab Indexed 2), that are sort of important, and neither of them should have a value Null, when the user wants to close this form.
How would you do this?
At present I tried it with codes in LostFocus events of the bove controls, which should take care of this issue for me, But they do not work all the times, Here are those codes;
Private Sub InvoiceID100_LostFocus()
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
If IsNull(Me.InvoiceID100) Or Me.InvoiceID100 = "" Then
strMsg = "You must Enter an Invoice No. A Date Or Check No.."
strTitle = "Invoice Number Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Me.ReffrenceID.SetFocus
Me.InvoiceID100.SetFocus
Cancel = True
End If
End Sub
Private Sub Combo144_LostFocus()
Dim strMsg As String
Dim strTitle As String
Dim intStyle As Integer
Dim MyResp As Integer
If (IsNull(Me!Combo144)) Then
strMsg = "You must select a Customer!"
strMsg = strMsg & vbCrLf & "If you want to choose it from the ComboList, press Yes."
strMsg = strMsg & vbCrLf & "Other wise Press No, And Just Enter it"
strMsg = strMsg & vbCrLf & "In Order to close the Form Press Cancel"
strTitle = "Bill To Customer Required"
intStyle = vbYesNoCancel + vbQuestion
MyResp = MsgBox(strMsg, intStyle, strTitle)
If (MyResp = vbNo) Then
Me.Combo144.Value = "Guest"
Me.InvoiceID100.SetFocus
ElseIf (MyResp = vbYes) Then
Me.CompanyName.SetFocus
Me.Combo144.SetFocus
ElseIf (MyResp = vbCancel) Then
DoCmd.Close acForm, "Sales", acSaveNo
End If
End If
End Sub
There are 2 problems with these codes;
1. When the Combo144 is not Null, But InvoiceId100 is null and the user decides to close this forms. The InvoiceId100 msgBox Pops Up for 3 times, But the form closes after the third one, Well the user should not be able to close at all.
2. Also In my combo144 , when the user gets the Bove MsgBox and chooses to push the Cancel Button (The button that should close the form), the form does not closes and the curser gets focused on to next Control.
What are the problems with the above codes?
Best Regards
Sanan