RecordSource property

  • Thread starter Thread starter kiki
  • Start date Start date
K

kiki

Hi
How can I change forms record source with VBA code? On first Form I have two
buttons, and I want them to open the same (new) Form but with different
Record Sources (different Queries). I have tried with RecordSource Property
but with poor results :))
I am using Access97.

Thanks in advance
 
How can I change forms record source with VBA code? On first Form I have two
buttons, and I want them to open the same (new) Form but with different
Record Sources (different Queries). I have tried with RecordSource Property
but with poor results :))
I am using Access97.

Well, the only way to change a form's recordsource is to change the form's
RecordSource property (of course, if the called form is opened modal, your
calling code will stop until after the called form is closed and you can't do
anything to that form's properties). Have you tried the following syntax?:

'************EXAMPLE START
'You can open the form, but not modally (acDialog)
DoCmd.OpenForm "Form2"
'Change the called form's recordsource
Forms("Form2").RecordSource = "qryAlternateRSQuery"
'************EXAMPLE END
 
... and I want them to open the same (new) Form but with different
I guess that I really didn't read that closely enough - my solution won't work.
Offhand, I don't really have an immediate answer for that one other than to save
a copy of the form with a different name and open that, instead.
 
Won't work? Should work....but you do need to requery the form after you set
the recordsource to a new text string.
 
Ken

There is no need to requery when a new RecordSource is assigned as Access
will automatically do a Form.Requery.
 
Assume the 2 RecordSources are of the SAME structure, i.e. same number of
Fields and same Field names, try:

1. Design the frmTwo as if it is a bound Form to one of the Required
RecordSource. Just before you save frmTwo, change the RecordSource Property
to blank.

2. In frmOne with 2 CommandButtons, use the Click Event like:

***Untested air-code***
Private Sub cmdOpenFrmTwoWithRSCOne()
DoCmd.OpenForm "frmTwo"
DoEvents
DoEvents
Forms!frmTwo.RecordSource = "...."
End Sub
***

and similar code for cmdOpenFrmTwoWithRSCTwo
 
Won't work? Should work....but you do need to requery the form after you set
the recordsource to a new text string.

You're right, of course. I just succeeded in confusing the second instance of
myself.

<BG>
 
.... ok!

--
Ken Snell
<MS ACCESS MVP>

Van T. Dinh said:
Ken

There is no need to requery when a new RecordSource is assigned as Access
will automatically do a Form.Requery.
 
Back
Top