Load record in form and not data sheet using query

riggsd

Board Regular
Joined
Jan 29, 2003
Messages
143
How do I run a query with a button and get it to load the found record into the form and not bring up a data sheet?

I created the button to run the query and it finds the correct record, but I need it to load the record into my form fields and not in a datasheet.

I'm assuming this would be done using VBA but I don't know how to do that and the information I've found hasn't done what I need to do.

Thanks in advance.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,964
Office Version
  1. 365
Platform
  1. Windows
Just have your button open the Form you want, and use your Query as the Data Source of that Form.
 

riggsd

Board Regular
Joined
Jan 29, 2003
Messages
143
Thanks, that worked. I haven't used Access in almost 10 years so have forgotten way too much.
 

riggsd

Board Regular
Joined
Jan 29, 2003
Messages
143
While it works, I can't get it to not open the form if the combo boxes are empty. I've tried adding that to the embedded macro as an if statement, with the open form in the else section but that doesn't seem to be working.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,964
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

I seldom use embedded macros. Doesn't give you enough control.

You can start out using a macro to get your "basic" functionality. Then I would recommend converting that macro to VBA code by using the "Convert Macros to Visual Basic" functionality. There you can add IF statements and the like to get more control over the process. Then have your Control Button run that VBA code instead of the Macro.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,964
Office Version
  1. 365
Platform
  1. Windows
I think that may sometimes depend on whether or not the fields are bound or not.

There is an easy way to find out - try it and see which one works!
That is a lot of what programming is all about, trial and error. So don't be afraid to try it out.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,826
Messages
5,855,868
Members
431,771
Latest member
CoryMelth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top