Command Button Event Procedure Error (1 Viewer)

nfi2020

New member
Local time
Today, 23:08
Joined
Apr 6, 2020
Messages
9
Hello,

I suspect this is just me not knowing what I'm doing (again), but...

I have a form, which has a subform on it. In that subform, I have two command buttons, which I'm attempting to turn into navigation buttons by adding the following code into their OnClick events as [Event Procedure]'s:

Code:
Private Sub cmdPrev_Click()
    'prevent form from adding new record
    Me.AllowAdditions = False
    
    'attempt to navigate to prev record
    On Error Resume Next
    DoCmd.RunCommand acCmdRecordsGoToPrevious
    
    Select Case Err.Number
        Case 0
            'no error
        Case NO_NEXT_RECORD
            'first record reached
        Case Else
            'unexpected error
            MsgBox Err.Description, vbExclamation, "Error"
    End Select
    
End Sub

..and a similar procedure for the "Next" button.

However, Access keeps throwing the following error when I click on either button:

OLE_Error.png


I'm pretty certain it's not the navigation code that's the problem - why can't I called a code block/Event Procedure from a command button this way?

Thanks for any help :confused:
 

Ranman256

Well-known member
Local time
Today, 18:08
Joined
Apr 9, 2015
Messages
4,337
These buttons already exist in the navigation at the bottom of the form.
No need to program it.

You turned off errors,then put in a MsgBox to show errors.
Which is it? Remove the error msgbox.

If there is still an error,then it's a control on the form,not the code.
 

bob fitz

AWF VIP
Local time
Today, 23:08
Joined
May 23, 2011
Messages
4,721
If you want to create your own navigation buttons then the easiest way would be to use the wizard in form design.

See how here: Create Navigation Buttons
 

nfi2020

New member
Local time
Today, 23:08
Joined
Apr 6, 2020
Messages
9
These buttons already exist in the navigation at the bottom of the form.
No need to program it.

Thanks; I hear what you say - the navigation bar confuses the intended users, though, so I'm using simple command buttons to make the navigation more obvious.

You turned off errors,then put in a MsgBox to show errors.
Which is it? Remove the error msgbox.

The error handling in the event procedure will just warn the user that the first/last record has been reached. The error attached to the previous post is being raised by "Microsoft Access", as you can see from the title bar. The error handling in my code won't catch application-level errors, which shouldn't ever happen, really.

If there is still an error,then it's a control on the form,not the code.

With the greatest respect, I'm confident it's not the code. The error being raised suggests an OLE/ActiveX problem (the error message text). My question is why this error is happening, when this is simply a command button attempting to call code via its _OnClick event.
 

nfi2020

New member
Local time
Today, 23:08
Joined
Apr 6, 2020
Messages
9
If you want to create your own navigation buttons then the easiest way would be to use the wizard in form design.

See how here: Create Navigation Buttons
Hi Bob,

that would be handy - I don't get the wizard that the woman on this video gets when she adds a button, though - my version of access (Office 365) just dumps a button on the screen and calls it Command75 or similar...

I'm hunting through the UI for it, though...
 

bob fitz

AWF VIP
Local time
Today, 23:08
Joined
May 23, 2011
Messages
4,721
Hi Bob,

that would be handy - I don't get the wizard that the woman on this video gets when she adds a button, though - my version of access (Office 365) just dumps a button on the screen and calls it Command75 or similar...

I'm hunting through the UI for it, though...
Perhaps this will help with the wizard: Toggle Wizard
 

nfi2020

New member
Local time
Today, 23:08
Joined
Apr 6, 2020
Messages
9
I was just about to post that exact video :)

My problem is the second one this chap has - God, this is a minefield!💥

Again, thanks for pointing me in the right direction!

👍
 

Minty

AWF VIP
Local time
Today, 23:08
Joined
Jul 26, 2013
Messages
10,371
@isladogs has some excellent and easily understood code for making universal record navigation button.
Have a look at some of his sample databases either here or on his website.

I personally like to check what record you are on and disable/enable the button appropriately eg. on the last record then the next or goto last button is disabled.
Use the on-current event to check the record you are on.
Have a separate button to add new records.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:08
Joined
May 7, 2009
Messages
19,230
add option explicit to your code and compile your vba, then it will point yout error.
 

missinglinq

AWF VIP
Local time
Today, 18:08
Joined
Jun 20, 2003
Messages
6,423
While this type of error is usually associated with the opening a Form, it apparently can be caused by all kinds of things, and, to the best of my knowledge, it is very seldom, if ever, actually connected with communicating with a OLE server or ActiveX Control!

The most common cause, going by what I've seen online for the past twelve years, has to do with using a non-English language with Access, and the need to set the language for non-unicode programs to that foreign language. Are you using a non-English language?

And always a possible solution, when things suddenly go phooey, for no apparent reason, is to create a new, blank Access file and Import everything into it.

Linq ;0)>
 

nfi2020

New member
Local time
Today, 23:08
Joined
Apr 6, 2020
Messages
9
Hello all,

thanks very much for your help with this - all suggestions made are very helpful and much appreciated :)


:unsure: What is that problem

I was trying to put the command buttons on a subform, instead of actually editing that form... :rolleyes:
...it's one of those things that seems obvious that it'd cause a problem after it's been pointed out to you...
 

Users who are viewing this thread

Top Bottom