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.
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,456
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
54,456
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
54,456
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,969
Messages
5,525,960
Members
409,673
Latest member
Riseee

This Week's Hot Topics

Top