Form_Open Event

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
 
S

stefan hoffmann

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 <--
 
R

Rick Brandt

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.
 

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