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

Current record on form is not being updated.

Status
Not open for further replies.

Chaddaman

Technical User
Jul 17, 2003
5
CA
I currently have a form that has a number of fields that when changed will run a macro that will change the data in the tables for other fields for that particular record.

However, in order for the changes to be visible on the form The macro must first go to the next record, continue to run, then before the macro is finished go back to the previous record to see the changes in the form.

How can I make it so I do not have to go to the next record and then back agian in order to see the changes in the form for the current record.

 
Add this code to the line before calling the Macro

DoCmd.RunCommand accmdSaveRecord

PaulF
 
I am running the macro from the "After Update" property of the fields. Where do I find the call to the macro. When I view the code for the form all I see is the code for the buttons. How do I view the code for the other properties on the form or fields so I can insert the above line of code.
 
If I read this correctly (and I probably am not), you are selecting the Macro Name in the AfterUpdate Event, and you know little about using code in the code module behind the Form. You have to select [Event Procedure] from the dropdown list associated with the AfterUpdate Event instead of the Macro Name. Then Click on the Build button (with ...) next to the button where you selected the [Event Procedure] from, this will put you in the code window. Add

DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunMacro "YourMacroNameGoesHere"

between the lines
Private Sub YourControlName_AfterUpdate()

and

End Sub


You'd have to do this for each Control you currently have a Macro called from.

Also if the fields being changed by the Macros are also on this same form, you'll need to also provide a line to refresh the form, so you'd also have to add

Me.Refresh

to each of the Controls.

One more thing.. if the Macros only change data on the same Form, you can do the update in code without having to call a Macro. Example, you want to change the data in TextBox txtFieldB to match the data you just inputted into TextBox txtFieldA, instead of the DoCmd.RunMacro command, you use

txtFieldB = txtFieldA

then all you have to do is the Me.Refresh, because you don't have to Save the Record until you're finished and move off of it or exit the Form.

Depending on how you exit the Form, you might want to Add the code to save the data as part of the Form's Close Event.

Private Sub Form_Close()
If Me.Dirty Then 'Changes Made
DoCmd.RunCommand acCmdSaveRecord
End If
End Sub


PaulF
 
Paul,

Thanks, big help...one more thing I am fairly new to coding in access so could you tell me where I could find avalible API information that describes what methods are avaliable and what they do...ie) DoCmd.RunCommand accmdSaveRecord

thanks
 
DoCmd is not an API call, its ACCESS...
Search in the Help Files for "Object Browser", or .. when you are in a code window you can highlight an action (i.e. RunCommand and press F1, and you should see a description of it.

PaulF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top