Link to home
Start Free TrialLog in
Avatar of kbay808
kbay808Flag for United States of America

asked on

How to trigger the next record button on an access form via vba?

I’m trying to call the below macro from another module and it does work, but it’s a hit or miss.  Is there a better way to do it?

Public Sub btnNextRecord_Click()
    DoEvents
    DoCmd.GoToRecord , , acNext
End Sub

Open in new window


Just in case it matters, here is how I’m calling it.
Call Forms("frmMyTicketAudits").btnNextRecord_Click

Open in new window

Avatar of PatHartman
PatHartman
Flag of United States of America image

If you want to make common code, put it into a standard module.  Forms are classes and they are not available unless the form is open.
Avatar of kbay808

ASKER

I will always have the form open and I'm calling it from a standard module.
It only makes sense to call it from a form.  in a standard module, you don't have a bound recordset which is what this code affects.
Avatar of kbay808

ASKER

The reason why I'm calling it from a standard module is because I am calling it from Excel.
Can you tell us what you are trying to do with this code and why you are running it in Excel.  If you are attempting to process a recordset, this is the wrong approach.  You would simply open a recordset using ADO and process that in EXCEL without automating Access.
Avatar of kbay808

ASKER

I have an excel file that compiles and processes that data.  I have code that updates all of the fields in an access form from excel that works great.  The only thing that I can’t do consistently is click the next record.  My goal is to be able have the user not have to go back and forth between excel and access.  The access form will always be open during this process.
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
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 kbay808

ASKER

You way make more sense.  I will work on doing it that way.
Avatar of kbay808

ASKER

Thanks for your help
Glad to help.