Log in

View Full Version : VBA problem..



A9992736
12-10-2012, 10:37 PM
How Can I go about making the msgbox appear if any of the conditions is wrong?? Please assist


Private Sub cmd_LO_PBA_Facility_Click()
On Error GoTo Err_Cmd_LO_PBA_Facility_Click
Me.Refresh
Dim stDocName As String

If cmb_Product_Type = "PBA Facility" Then

If Not IsNull(RCF_Limit) Then

If Not IsNull(FX_Option_Limit) Then

If Not IsNull(Security_Option_Limit) Then

If Not IsNull(PBA_Account_No) Then

If Not IsNull(Interest_Rate) Then

stDocName = "PBA_Facility_LO"
DoCmd.OpenReport stDocName, acPreview

Else:
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus

End If

End If

End If

End If

End If

End If

Exit_Cmd_LO_PBA_Facility_Click:
Exit Sub
Err_Cmd_LO_PBA_Facility_Click:
MsgBox Err.Description
Resume Exit_Cmd_LO_PBA_Facility_Click

End Sub

lenius
12-11-2012, 05:32 AM
I would break down the if blocks into sections. This way you can customize what the msgbox displays. For example the first if block you can change the message to "Please check your input at the PBA Facility on the Facility tab." You can also set the focus to the exact area that met the conditions. I hope that helps.

Private Sub cmd_LO_PBA_Facility_Click()
On Error GoTo Err_Cmd_LO_PBA_Facility_Click
Me.Refresh
Dim stDocName As String

If cmb_Product_Type = "PBA Facility" Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End IF
If Not IsNull(RCF_Limit) Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End IF
If Not IsNull(FX_Option_Limit) Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End IF

If Not IsNull(Security_Option_Limit) Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End IF

If Not IsNull(PBA_Account_No) Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End IF
If Not IsNull(Interest_Rate) Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End if

stDocName = "PBA_Facility_LO"
DoCmd.OpenReport stDocName, acPreview



Exit_Cmd_LO_PBA_Facility_Click:
Exit Sub
Err_Cmd_LO_PBA_Facility_Click:
MsgBox Err.Description
Resume Exit_Cmd_LO_PBA_Facility_Click

End Sub

A9992736
12-11-2012, 07:03 PM
I would break down the if blocks into sections. This way you can customize what the msgbox displays. For example the first if block you can change the message to "Please check your input at the PBA Facility on the Facility tab." You can also set the focus to the exact area that met the conditions. I hope that helps.

Private Sub cmd_LO_PBA_Facility_Click()
On Error GoTo Err_Cmd_LO_PBA_Facility_Click
Me.Refresh
Dim stDocName As String

If cmb_Product_Type = "PBA Facility" Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End IF
If Not IsNull(RCF_Limit) Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End IF
If Not IsNull(FX_Option_Limit) Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End IF

If Not IsNull(Security_Option_Limit) Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End IF

If Not IsNull(PBA_Account_No) Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End IF
If Not IsNull(Interest_Rate) Then
MsgBox "Please check your input at Revolving Credit Facility tab"
Me!RCF_Limit.SetFocus
Exit sub
End if

stDocName = "PBA_Facility_LO"
DoCmd.OpenReport stDocName, acPreview



Exit_Cmd_LO_PBA_Facility_Click:
Exit Sub
Err_Cmd_LO_PBA_Facility_Click:
MsgBox Err.Description
Resume Exit_Cmd_LO_PBA_Facility_Click

End Sub


Anw, how do you use the exit sub thing?

Now I'm trying to tweak a bit, meaning if a field is null then the msgbox will appear and setfocus to the particular null-field.

I want it to check one by one, for example check:

If cmb_Product_Type = "PBA Facility" Then

If RCF_Limit = Null Then
MsgBox "Please fill in RCF Limit!"
Me!RCF_Limit.SetFocus

Else
If FX_Option_Limit = Null Then
MsgBox "Please fill in FX Option Limit!"
Me!FX_Option_Limit.SetFocus
End If

End If

End If

In addition, I want to preview a document for e.g. stDocName if all the checkings are false which means all fields are filled in thus there is no need for any MsgBox to appear and setfocus to any field.

Please assist.

mrojas
12-17-2012, 08:10 AM
In your code:
If RCF_Limit = Null Then
MsgBox "Please fill in RCF Limit!"
Me!RCF_Limit.SetFocus

simply add Exit Sub after the .SetFocus statement. Do this for each If statement.

A9992736
12-26-2012, 06:13 PM
In your code:
If RCF_Limit = Null Then
MsgBox "Please fill in RCF Limit!"
Me!RCF_Limit.SetFocus

simply add Exit Sub after the .SetFocus statement. Do this for each If statement.

Thanks mrojas for your assistance.