A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

if function call is true exit sub



 
 
Thread Tools Display Modes
  #1  
Old November 12th, 2009, 02:04 PM posted to microsoft.public.access.forms
deb
external usenet poster
 
Posts: 898
Default if function call is true exit sub

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.

--
deb
  #2  
Old November 12th, 2009, 08:28 PM posted to microsoft.public.access.forms
ghetto_banjo
external usenet poster
 
Posts: 325
Default if function call is true exit sub

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
  #3  
Old November 12th, 2009, 08:45 PM posted to microsoft.public.access.forms
deb
external usenet poster
 
Posts: 898
Default if function call is true exit sub


I was able to figure this out.

Took me a while thouugh...
--
deb


"deb" wrote:

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.

--
deb

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:44 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.