Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switching Between Forms -- PLEASE HELP!!! - thanks

Status
Not open for further replies.

FeedMeAccess

IS-IT--Management
Aug 31, 2000
6
US
I would like to set-up the following scenario:

My insertion point is on the last name field of the record John Smith in a general information subform. I then click a button that executes a macro to close the general information form and open let's say the medical information form. I would like the medical information form being opened to automatically bring up the record John Smith with the insertion point in the last name field. Can this solution be added to the current commands in the macro attached to the button that opens and closes the forms? I am not an Access Pro but am constantly learning. Any help would be greatly appreciated.

THANKS!
 
Yes, it can be added. You need to use the SetFocus method. Do you want all records available on the medical form or just the one for John Smith? That would determine how we would show the John Smith record, using Filter or RecordsetClone

Check out SetFocus, Filter, and RecordSetClone in the Help files. If you want, post your existing code and we'll show you how to edit it.

 
I don't work with macros but the wizard for command buttons can do this for you. The only additional code you need to write is to close the main form (or make it invisible) while you are on the other form. Let me know if you havent worked with code yet.
 
Kathyrn,

Thanks for your suggestion but I am still somewhat confused about SetFocus, Filter, and RecordSetClone. I create a macro that says: (not in programming language but in the macro creater)

Close Main Screen Form

Open Medical Information Form

What do I use here? Run Code and use the expresion builder?

If I am to use the expression builder, I don't quite understand how Access will know what record to go to if the first thing that I am doing is closing the form. Any thoughts?

Bryant
 
I'm sorry, I didn't realize that you really meant a macro. A number of people refer to macros when they mean code.

I don't know if that is possible in Macros, but I doubt it.

To do this you are going to have to go to code. You can have Access translate your existing Macro into VBA code. With the Macro selected, choose File,SaveAs... and choose Code (or whatever the exact wording is. Look under the Modules tab and you will see your translated code.

Post the resulting code and we'll work on it.
 
I pasted the code below:


Function SetFocusTry()
On Error GoTo SetFocusTry_Err

DoCmd.Close acForm, "First Screen Form"
DoCmd.OpenForm "GeneralInformationForm", acNormal, "", "", , acNormal
Call Forms!GeneralInformationForm!LastNameLabel.SetFocus


SetFocusTry_Exit:
Exit Function

SetFocusTry_Err:
MsgBox Error$
Resume SetFocusTry_Exit

End Function
 
I also tried this approach but I am getting an error message that says, "The object you referenced in the Visual Basic procedure as an OLE object, isn't an OLE object".

-- any thoughts??


Function Volibrawl()
On Error GoTo Volibrawl_Err

DoCmd.OpenForm "MedicalInformation (7-24)", acNormal, "", "", , acNormal
DoCmd.GoToControl "ID"
DoCmd.FindRecord Forms!generalinformationform.ID, acEntire, False, , False, , True


Volibrawl_Exit:
Exit Function

Volibrawl_Err:
MsgBox Error$
Resume Volibrawl_Exit

End Function
 
A couple of things:


Did you really want to set the focus to a Label in the following line?
Call Forms!GeneralInformationForm!LastNameLabel.SetFocus


I would move the code that affects the newly opened form to that form's load event, so the code would look like:

me!YourcontrolName.setfocus
DoCmd.FindRecord Forms!generalinformationform.ID, acEntire, False, , False, , True




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top