why wont this work? want to open different form if no records in subform

holden_1

Registered User.
Local time
Today, 00:39
Joined
Feb 2, 2005
Messages
38
Private Sub open_report_Click()
On Error GoTo Err_open_report_Click

Dim stDocName As String
Dim stLinkCriteria As String


If Forms![frm_problem]![sfrm_problem_report].Form![Report_ID] <> 0 Then
stDocName = "frm_report_review"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Else

If IsNull(Forms.frm_problem.Responsibility_ID) Then
MsgBox "You have not attributed responsibility"
End If

If (Forms.frm_problem_amend.Responsibility_ID) = 1 Then
stDocName = "frm_new_report"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

End If

Exit_open_scar_Click:
Exit Sub

Err_open_scar_Click:
MsgBox Err.Description
Resume Exit_open_scar_Click
End Sub


So, i thought this would work by if there is a record in sfrm_problem_report, i.e. report_ID is not null, then it will see if responsibility has been assigned and if yes, then it'll open frm_new_report instead. Doesn't work. i get "you entered an expression that has no value". the first bit works, but not the "else" bit. i.e. if there are records present in the subform, then review report opens, but error message if there are no records in the subform.

please help!

cheers, Rob
 
Can you indicate which line is failing and giving the error message. That should point you to the cause of the problem
 
hi, all lines work individually. i think the problem is with the "else" i.e. if the arguement

"If Forms![frm_problem]![sfrm_problem_report].Form![Report_ID] <> 0 Then"

is any other case than not "0" then i get error message "you entered an expression that has no value". However,

If IsNull(Forms.frm_problem.Responsibility_ID) Then
MsgBox "You have not attributed responsibility"
End If

If (Forms.frm_problem_amend.Responsibility_ID) = 1 Then
stDocName = "frm_new_report"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

does work on its own. i'm stumped!
 
Remember that in Access

If A = 0 or A<>0

will only return values of A that are not Null.

Have you tried single stepping through your code until the error occurs. You need to find the precise expression that it doesnt like. The Else statement looks fine

If you post your code within code tags then formatting is preserved

Code:
Private Sub open_report_Click()
On Error GoTo Err_open_report_Click

Dim stDocName As String
Dim stLinkCriteria As String


If Forms![frm_problem]![sfrm_problem_report].Form![Report_ID] <> 0 Then
   stDocName = "frm_report_review"
   DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
   If IsNull(Forms.frm_problem.Responsibility_ID) Then
      MsgBox "You have not attributed responsibility"
   End If
   If (Forms.frm_problem_amend.Responsibility_ID) = 1 Then
     stDocName = "frm_new_report"
     DoCmd.OpenForm stDocName, , , stLinkCriteria
   End If

End If

Exit_open_scar_Click:
Exit Sub

Err_open_scar_Click:
MsgBox Err.Description
Resume Exit_open_scar_Click
End Sub
 

Users who are viewing this thread

Back
Top Bottom