charlie442
Registered User.
- Local time
- Today, 21:10
- Joined
- Jan 14, 2011
- Messages
- 53
Hi
I have an input box which directs users to a Form (Frm_Risk_Profile) to update a Case ID specified in the input box. I only want this to happen if the case ID is present in Tbl_Profiling_Cases. If it is not then the user should be redirected to the Main Switchboard form (Frm_Main_Switchboard). I have tried to accomplish this using a dlookup of the case ID in Tbl_Profiling_Cases embedded in an IF statement. However the criteria referencing the Temp variable is causing problems.
Any help greatly appreciated. The code I have written is as follows:
Private Sub OpenRiskProfileForm_Click()
'This function allows the user to open the risk profile form to a particular case ID.
Dim stSql As String
Dim Temp$
DoCmd.Close acForm, Me.Name
'InputBox prompts user to enter Case ID for the form they wish to open.
Temp = InputBox("Enter Case ID", "Search for Case ID", "Case ID")
If StrPtr(Temp) = 0 Then 'redirect to main switchboard if cancel is pressed on switchboard
DoCmd.OpenForm "Frm_Main_Switchboard"
Else
If DLookup("Case_ID", "Tbl_Profiling_Cases", strTemp) Is Null Then 'redirect to main switchboard if case id is null
MsgBox "Case_ID Not Opened!"
DoCmd.OpenForm "Frm_Main_Switchboard"
Else
If DLookup("Case_ID", "Tbl_Profiling_Cases", strTemp) Is Not Null Then 'open form to record that matches the Case ID entered by user.
DoCmd.OpenForm "Frm_Risk_Profile", acNormal, , "[Case_ID]='" & stInput & "'", acFormEdit
End If
End If
End If
End Sub
I have an input box which directs users to a Form (Frm_Risk_Profile) to update a Case ID specified in the input box. I only want this to happen if the case ID is present in Tbl_Profiling_Cases. If it is not then the user should be redirected to the Main Switchboard form (Frm_Main_Switchboard). I have tried to accomplish this using a dlookup of the case ID in Tbl_Profiling_Cases embedded in an IF statement. However the criteria referencing the Temp variable is causing problems.
Any help greatly appreciated. The code I have written is as follows:
Private Sub OpenRiskProfileForm_Click()
'This function allows the user to open the risk profile form to a particular case ID.
Dim stSql As String
Dim Temp$
DoCmd.Close acForm, Me.Name
'InputBox prompts user to enter Case ID for the form they wish to open.
Temp = InputBox("Enter Case ID", "Search for Case ID", "Case ID")
If StrPtr(Temp) = 0 Then 'redirect to main switchboard if cancel is pressed on switchboard
DoCmd.OpenForm "Frm_Main_Switchboard"
Else
If DLookup("Case_ID", "Tbl_Profiling_Cases", strTemp) Is Null Then 'redirect to main switchboard if case id is null
MsgBox "Case_ID Not Opened!"
DoCmd.OpenForm "Frm_Main_Switchboard"
Else
If DLookup("Case_ID", "Tbl_Profiling_Cases", strTemp) Is Not Null Then 'open form to record that matches the Case ID entered by user.
DoCmd.OpenForm "Frm_Risk_Profile", acNormal, , "[Case_ID]='" & stInput & "'", acFormEdit
End If
End If
End If
End Sub