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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro Not Firing for Sub Form?

Status
Not open for further replies.

JJman

Technical User
May 8, 2003
89
IN
I have a sub form with a GoToRecord macro (to a new record) fired by the On Open event. When the sub form is opened by itself it goes to a new record just fine, but when the sub form is opened as part of the main form it does not. The sub form is not linked to the main form via Link Child Field/Link Master Field (nor do I wish it to be). Can anyone help?
 
Sure. I don't know why its not working for you on the subform when embedded in the parent form. Maybe it has something to do with using a macro, but try this:

Private Sub Form_Open(Cancel As Integer)
RunCommand acCmdRecordsGoToNew
End Sub

The above code goes in the On Open event of the child form. This works perfectly for me.

If you don't want previously added records to be visible in the sub form, its even easier: you can set the child form's DataEntry property to True.

 

Thanks for the advice. Oddly, this didn't work for me either, but behaves the same way as the macro did. It works fine when I open the sub form by itself, but not when it opens as part of the main form. I also set the data entry property of the sub form to yes and, oddly again, all records still showed when it opened as part of the main form, but when opened by itself, the subform only showed a blank new record. I just don't get it.... Thanks again for trying, though!
 
Never heard of such a thing! Well, try checking the properties of the subform conrtol.

Are you opening the mainform with code? If so, make sure your not specifying the open mode, so that the forms control how they open.

Also you might try deleting the subform control and adding it again. Maybe it got corrupted at some point.
 
Maybe selecting the macro to run at the 'On Load' variable within the master form properties will work? Just a thought...
 

Well, I've tried each suggestion and, after much hair pulling it seems I've discovered that there is only one event (related to the form launching) that will fire the macro; On Current. For whatever reason, it completely ignores the On Open, On Load, etc. It's finally doing what I want it to, but why the other events weren't working is still a mystery... Thank you each for your help!
 
I guess that makes sense, but I don't remember ever running into the problem. It makes sense because until you're actually IN the recordset, you can't move to a particular record in that recordset.

It worked for me in the OnOpen. But then, I used code and you used a macro. Try using the code from my response above instead of the macro and see if it works. It would be good to start using code instead of macros, anyway. Most, if not all, commands that are available in Macros are also available in code. Check out help "DoCmd" and "RunCommand". One way to see all the macro-like actions available in DoCmd and RunCommand is to go into code, type one of those commands and then hit the space bar. The entire list will appear and you can browse it. Then, if you want to see some help (especially with DoCmd), you can just put your cursor in the action following the DoCmd and press F1.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top