Form_Open Event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that uses criteria from another form (fProspects) as part of
the SQL for it's record source. I've added the following code to Cancel the
form from opening if fProspects isn't open, but it still prompts for the
fields in fProspects before closing the form.

Any ideas how I can get it to Cancel the open before trying to create the
data connection?

Private Sub Form_Open(Cancel As Integer)

'close if the Prospects form is not loaded
If CurrentProject.AllForms("fProspects").IsLoaded = False Then

Cancel = True

End If

End Sub
 
hi,
Any ideas how I can get it to Cancel the open before trying to create the
data connection?
Use a unbound form and set the record source in the code.
Private Sub Form_Open(Cancel As Integer)
'close if the Prospects form is not loaded
If CurrentProject.AllForms("fProspects").IsLoaded = False Then
Cancel = True
Else
me.RecordSource = "SELET * FROM ... WHERE ID = " & fProspects![ID]
End If
End Sub


mfG
--> stefan <--
 
MChrist said:
I have a form that uses criteria from another form (fProspects) as
part of the SQL for it's record source. I've added the following
code to Cancel the form from opening if fProspects isn't open, but it
still prompts for the fields in fProspects before closing the form.

Any ideas how I can get it to Cancel the open before trying to create
the data connection?

Private Sub Form_Open(Cancel As Integer)

'close if the Prospects form is not loaded
If CurrentProject.AllForms("fProspects").IsLoaded = False Then

Cancel = True

End If

End Sub

In design view of the form remove the RecordSource. In your Open code set
the RecordSource when the other form is open.
 
Back
Top