David92595
Registered User.
- Local time
- Today, 03:27
- Joined
- Jun 28, 2011
- Messages
- 44
So I'm almost done with a piece of script. My boss has asked me to add a error MsgBox, and I have no idea how to do it or where to put it in the script...before, after, do I have to put it after every If statement???
explination of the script:
The macro "Find_on_click_TS2" just looks at a textbox in another form in a then all the "%% fees & Costs". All of the "%% fees & costs" forms are seperate from each other, but in the same DB.
Here is the script:
Private Sub Command152_Click()
On Error GoTo Command152_Click_Err
If State = "AZ" Then
DoCmd.OpenForm "AZ Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "CA" Then
DoCmd.OpenForm "CA Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "ID" Then
DoCmd.OpenForm "ID Fees&Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "NV" Then
DoCmd.OpenForm "NV Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "NC" Then
DoCmd.OpenForm "NC Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "HI" Then
DoCmd.OpenForm "HI Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "OR" Then
DoCmd.OpenForm "OR Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "UT" Then
DoCmd.OpenForm "UT Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "WA" Then
DoCmd.OpenForm "WA Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "TX" Then
DoCmd.OpenForm "TX Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "CO" Then
DoCmd.OpenForm "CO Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "FL" Then
DoCmd.OpenForm "FL Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
Else
MsgBox "State Unknown"
End If
Command152_Click_Exit:
Exit Sub
Command152_Click_Err:
MsgBox Error$
Resume Command152_Click_Exit
End Sub
Any help would be greatly apprecheated. If you know of any other ways of stream lining the code, I'd love that too. I know it can be done, I'm just a bit of a noob at VB.
explination of the script:
The macro "Find_on_click_TS2" just looks at a textbox in another form in a then all the "%% fees & Costs". All of the "%% fees & costs" forms are seperate from each other, but in the same DB.
Here is the script:
Private Sub Command152_Click()
On Error GoTo Command152_Click_Err
If State = "AZ" Then
DoCmd.OpenForm "AZ Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "CA" Then
DoCmd.OpenForm "CA Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "ID" Then
DoCmd.OpenForm "ID Fees&Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "NV" Then
DoCmd.OpenForm "NV Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "NC" Then
DoCmd.OpenForm "NC Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "HI" Then
DoCmd.OpenForm "HI Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "OR" Then
DoCmd.OpenForm "OR Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "UT" Then
DoCmd.OpenForm "UT Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "WA" Then
DoCmd.OpenForm "WA Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "TX" Then
DoCmd.OpenForm "TX Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "CO" Then
DoCmd.OpenForm "CO Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
ElseIf State = "FL" Then
DoCmd.OpenForm "FL Fees & Costs"
DoCmd.RunMacro "Find_on_click_TS2"
ElseIf (Form.%% Fees & Costs.TS) <> "Find_on_click_TS2" Then
MsgBox "No Fees & Costs Exist for this TS #"
Else
MsgBox "State Unknown"
End If
Command152_Click_Exit:
Exit Sub
Command152_Click_Err:
MsgBox Error$
Resume Command152_Click_Exit
End Sub
Any help would be greatly apprecheated. If you know of any other ways of stream lining the code, I'd love that too. I know it can be done, I'm just a bit of a noob at VB.