How to Change the Data Source of a Form

M

magmike

How can you change the underlying query (not filter) of a form and is
it possible when the data source of a form is a table?

Thanks in advance!

magmike
 
J

Jeff Boyce

As a general practice, I base all my forms (and reports) on queries rather
than directly on tables. More flexibility that way...

You don't provide a specific context within which you are trying to change
the source, so this is a generic response:

Open the form in design view, open the properties window, find the ...
source property and change it to a new query/table.

Good Luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
J

Jerry Whittle

You could put something like this on the On Click event of a command button
on the form. "Emp2" is the name of the table or query.

Private Sub Command35_Click()
Me.RecordSource = "Emp2"
End Sub
 
A

Al Campagna

magmike,
This is such a simple question that I'm wondering if I'm missing
something here.
Perhaps you mean that you built a form using the wizard, and now you
need to make changes to the underlying Record Source?

The Record Source property for a form can be a table, a saved query, or
an internal query.
It can be changed at any time by going into form Design Mode, and
selecting another table or another saved query, in the Record Source
property of that form.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
M

magmike

You could put something like this on the On Click event of a command button
on the form. "Emp2" is the name of the table or query.

Private Sub Command35_Click()
    Me.RecordSource = "Emp2"
End Sub
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.







- Show quoted text -

Sorry, guys. My fault. I should have mentioned that I wanted to be
able to use the OnClick of a command or the AfterUpdate on a combo box
to change the data source of a form that I built, rather than using
the filter method. I certainly don't want my users going in to design
mode to do it!
 
J

Jeff Boyce

OK, now you've piqued my curiosity...

If a user is using a form, why would s/he need to change what (data source)
that form is based on?

Is there a chance you have a data structure that uses different tables (of
identical structure) to hold different sets of data?

Regards

Jeff Boyce
Microsoft Office/Access MVP


You could put something like this on the On Click event of a command
button
on the form. "Emp2" is the name of the table or query.

Private Sub Command35_Click()
Me.RecordSource = "Emp2"
End Sub
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.







- Show quoted text -

Sorry, guys. My fault. I should have mentioned that I wanted to be
able to use the OnClick of a command or the AfterUpdate on a combo box
to change the data source of a form that I built, rather than using
the filter method. I certainly don't want my users going in to design
mode to do it!
 
A

Al Campagna

magmike,
As my initial response indicated, I felt there was more to your question
than just "how to change a Record Source"...
I would never suggest that a user be allowed to go into Design mode to
make changes!

Now that you have clarified the issue...Jerry Whittles response is what
you need, but... I agree with Jeff Boyce that changing the RecordSource "on
the fly", is a bit unusual. I'd also be interested to know why you're
finding it necessary to do so.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."


You could put something like this on the On Click event of a command
button
on the form. "Emp2" is the name of the table or query.

Private Sub Command35_Click()
Me.RecordSource = "Emp2"
End Sub
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.







- Show quoted text -

Sorry, guys. My fault. I should have mentioned that I wanted to be
able to use the OnClick of a command or the AfterUpdate on a combo box
to change the data source of a form that I built, rather than using
the filter method. I certainly don't want my users going in to design
mode to do it!
 
Top