Link to home
Start Free TrialLog in
Avatar of jetera
jeteraFlag for Canada

asked on

Macro to open form, find record and open another form based on record found

Hi everyone,
I have a main menu form "frmMainMenu"  that has a combo box "cmbPeople" on it that list the people and users select a person, then hit "Go" and the main form "FrmMain" opens and the rest of the information can be entered.
Now I want the users to be able to add a new person quickly - like add their name and bdate, then click "Continue" and navigate to the frmMainMenu, find the newly added person in the conbobox and then open frmMain with that information and then close the new form "frmAddNew", (it has a couple of fields, I also have a continue button on it. It is set to only allow data entry (Data Entry = yes). )

How can I do this?  Should I try and use a macro?

Thanks in advance!!!
Jetera
Avatar of dprager
dprager

below some code you can paste behind the eventprocedure of the button to click
where the table is ofcourse the table where you linked your listbox to.

dim Dbs as DAO.recordset
set rst = currentdb.openrecordset("table")
rst.add
rst!name = [texbox1]
rst!birthdate = [texbox2]
rst.edit
rst.update
rst.close

docmd.openform "rmMainMenu"

Good luck !!
Avatar of jetera

ASKER

This doesn't really work, when I open  "frmMainMenu"  that has a combo box "cmbPeople" on it I want to have it showing the name I just entered so that the user doesn't have to scroll through the list.  I was thinking of findrecord or gotto control - that's why i thought I should use a macro... can we change your code to do that?
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jetera

ASKER

Thanks - it works great!