INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Part of the code that I want to exe

Part of the code that I want to exe

(OP)
Part of the code that I want to execute when a particular command button is clicked upon, is to move to the first record of the form. This is a small form in which all 14 records of the small dataset in 'continuous' mode. The number of records never changes, as they are just settings to be used elsewhere, so we toggle them in this small form.
This command button is for setting them back to their defaults which are just stored in an unseen field in the same form. Hence the 'Set to Defaults' button just runs a little UPDATE SQL that changes 'Current_State' to 'Default'.
That all works fine with one caveat, which is that whatever the last record that was changed was doesn't update unless you have since left that record. Hence in my code before running the SQL, I want to move them out of that record.
I plan to do this by sending them to the first record and then to the next record (in case they were already on the first record). It is further noted that this form is a subform and the command button resides on this subform itself, not the parent form.

So, I use:
DoCmd.GoToRecord acDataForm, "AP_Parameter_Selection!AP_Parameter_Subform_Search_Fields" , acFirst

and I've tried every combination of using/not using quotes, brackets, not specifying parent form, using "Forms!", etc. that I can think of and nothing works.
In most variations I get an error message telling that the specified form is not open. What am I doing wrong?

RE: Part of the code that I want to exe

Forget that workaround. Simply commit the form changes to the database. Try adding
Me.dirty = false
before your code. This will commit the changes. If the command button is on the parent form then
me.YourSubformControlName.Form.dirty = false

RE: Part of the code that I want to exe


TRY

CODE --> VBA

docmd.GoToRecord acDataForm,me.name,acFirst 

RE: Part of the code that I want to exe

(OP)
The Me.Dirty thing worked great. A curious thing happens with this small block of code that I've not noticed happening elsewhere. I have a docmd.setwarnings (False) at the beginning of the code so it doesn't alert me about the changes it's going to make. As soon as I put in any other statement before the SQL run, it seems to disable it and the warnings come back on, so I had to place the setwarnings statement right before the SQL run. Not a big deal but rather odd.
Thanks for your help.

RE: Part of the code that I want to exe

Neither PWISE's code and your code will ever work. You can never refer to a subform by name. The only way to reference a subform is through its parent form and subform control. Assume your subform is called "SubA" and you open its parent form. If you looped the Forms collection you will only see the parent form in the collection of open forms. Another way to think of this is to put the same subform on two different forms or twice on the same form. If you tried to refer to it by name, which instantiation would you be talking about.

So if you want to reference a control on "SubA" opened as a subform on a parent form, you cannot call it by name
Forms("SubA").textBox1
you have to go through the parent form and its subformcontrol and then the subform in the subformcontrol
Forms("ParentForm").SubAControl.Form.textbox1

Your docmd code would work when called from the subform by simply
docmd.gotorecord ,,AcFirst

Since there is no way to supply a subform name this code without the first two arguments defaults to the active form.

RE: Part of the code that I want to exe

(OP)
Your docmd code would work when called from the subform by simply
docmd.gotorecord ,,AcFirst

When I tried this, it said that an argument wasn't optional. I'm happy with the Me.Dirty method for this instance, but I'm trying to understand why things do what they do.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close