if function call is true exit sub

D

deb

using access 03
Dirk Goldgar help me with a function that gives a message if the subform
does not have a child record. This works beautifully. Thank you Dirk!!
code below

Private Function RequireChildRecord(Optional Unloading As Boolean)
Dim GoBackID As Variant

GoBackID = Null

If Len(LastRecordID & vbNullString) > 0 Then
If (LastRecordID <> Nz(Me.ProjectID, 0)) Or Unloading Then

If DCount("*", "t51KeyMilestones", "ProjectID=" & LastRecordID)
= 0 Then

If MsgBox( _
"PM080 and PM670 Milestones are not entered! Go
Back?", _
vbExclamation + vbYesNo, _
"Milestone Entry Required") _
= vbYes _
Then
GoBackID = LastRecordID
End If

End If

End If
End If

If Not IsNull(GoBackID) Then
If Unloading Then
DoCmd.CancelEvent
End If
Me.Recordset.FindFirst "ProjectID=" & GoBackID
Else
LastRecordID = Me.ProjectID
End If

End Function

I have a Find Record button that opens a popup form that finds a record
using the below code when user clicks on record in popup.

Private Sub ShowRecord4_Click()
Dim Rst As DAO.Recordset
' Store the recordset for the form.
Set Rst = Forms!f040ProjectMain.RecordsetClone

' Locate the record for the selected.
Rst.FindFirst "ProjectID = " & List4

' Set the form's Bookmark property to move to the record.
Forms!f040ProjectMain.Bookmark = Rst.Bookmark

' Close the dialog box.
DoCmd.Close acForm, "f40ProjectGoTo"

End Sub

Now for my issue...
When the user clicks the Find Record button the msg is triggered by the
Function RequireChildRecord, as it should, however the popup form pops up.

How can I keep the pop up from popping up if the function call is true? If
there is no child records, prevent the popup.
 
G

ghetto_banjo

Well from the looks of it, the function call currently is not
considered true/false as it is not returning a value, it is only
calling a procedure.

Change the function definition to:

Private Function RequireChildRecord(Optional Unloading As Boolean) as
Boolean


then in the code "RequireChildRecord" becomes a boolean variable that
you can set
When you find out there is no child record, you can say:

RequireChildRecord = False


And if it does have a child record and you want the form to open then
set it to true to return back to the function.


Then back in your main function where you call this one:

If RequireChildRecord() then
docmd.openform .......
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top