Microsoft Access VBA on open error - vba

Basically I am populating my form with data from a database. For this I have an onopen event with just this code inside:
Me.Requery
Everything worked perfectly fine until yesterday, were out of the sudden an error occured. The error states:
The expression OnOpen you entered as the event property produced the following error: Instruction invalid outside of a type-block.
Aditional it says in the Discription:
The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]
There may have been an error evaluating the function, event or macro.
When I go to show help it says:
This error occurs when an event has failed to run because the location of the logic for the event cannot be evaluated. For example, if the OnOpen property of a form is set to =[Field], this error occurs because a macro or event name is expected to run when the event occurs.
However, when I click the message away, everything loaded correctly.
I am using:
-Microsoft Access 2013
Q&A:
Does your code compile successfully?
Yes, the rest works fine. It also loads everything into the form correctly. But Every time I start it, this info filed pops up.
EDIT: I just noticed that all my on click events throw the same error now.
Could you show the whole code?
I actually have everything else commented out to troubleshoot the error. If I delete the onopen event the info box disappears.

As mentioned in the comments, compilation can fix the problem by finding errors like wrong access modifiers
When compilation goes fine, one should delete the Form_Load function and let IDE recreate it. This fixed my problem thought apparently no change in code was observed.

Many thanks
My problem was naming a label with a Farsi name. After correcting it in English, the problem was solved

Related

On Load event firing when closing Access and throwing "can't move the focus to the control" error

I have an Access database where I have code on the On Load event of the main form to set focus to a textbox and load a 'new' record. The code is:
Private Sub Form_Load()
'Makes it so that when frmDiversion_Review loads, it defaults to a new record
DoCmd.GoToRecord , , acNewRec
Me!FromDate.SetFocus
End Sub
FromDate is an unbound date field used in a search/filter section on the header of the form.
I've split the database, and have an .accde file ready to go, but I've noticed that when I close Access when in the .accde file it gives me the following error:
"The expression On Load you entered as the event property setting produced the following error:
****NameOfDatabase**** can't move the focus to the control FromDate."
It does not give an error number.
The code is compiled, and I only get this error using the .accde file. I'm at a loss why the On Load event is even firing when I close Access. Any ideas?
A few weird scenarios may produce this (such as something relating to other forms being closed when you close out...) having references to this form that cause it to open. Hard to say from here.
But there is an easy out... just add this line at the start of the routine
On Error Resume Next
This is safe provided you know there are no real errors in the routine ever, excepting this annoying one that doesn't actually mean anything. If real errors can occur, you will no longer see them if you add this easy-out.
Personally, I'd prefer to find the cause and address it, not least because it seems other forms are trying to open this form while you're busy closing the app, which is an unsettling thought. But... when all else fails, it's a solution.

VBA Error handling dosen't work for one user in Excel 2016

I have a weird situation where a user is experiencing a run time error (which is expected and handled) except in this one case. From all the documentation that I've read for VBA error handling, if a sub procedure creates an error, the error is percolated up through the call stack until a procedure is found that has error handling and it is processed at that level. If no handler is found, then the run time error dialogue window is displayed. So...
Sub ProcedureA()
Try:
On Error Goto Catch
' No error handler in ProcedureB
ProcedureB
Catch:
If Err.Number <> 0 then
' Manages error from ProcedureB
End If
End Sub
This works for all users except one who had recently installed Excel 2016 (although there are other users with 2016 and no problems). In his case, the run time error dialogue window appears with the "scene of the crime" highlight pointing to a statement in ProcedureB (which has no error handler). My question then is if there is some setting in Excel or in its VBA options which would override the default VBA error handling behavior?
This isnt an issue with his Excel version. It is instead a setting within the VBE. From what I know, this isnt turned on by default, so either your user turned this setting on, or for one reason or another the default setting changed.
To fix this setting:
Open the VBE
Go to the Tools Menu (Alt-T)
Select Options (Alt-O)
Under the General Tab > Error Trapping you will want to select either 'Break in Class Module' (this allows you to see errors within class modules, if they occur. I highly recommend this setting.) or 'Break On Unhandled Errors' (nearly the same behavior, but it breaks within the calling routine and wont allow you to see the error as it happens within the class.)
Then you should be all set. What was happening was the VBE settings were overriding the error handling behavior which can be beneficial for debugging, but is not so beneficial when someone is actually running your app.

Windows Forms Editor Exception

I'm not even sure how to ask this question, but here goes. The design view of my windows forms object now crashes with the following error:
The control DevComponents.DotNetBar.Office2007RibbonForm has thrown an unhandled exception in the designer and has been disabled.
Exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Stack trace:
at DevComponents.DotNetBar.Office2007RibbonForm.WindowsMessageStyleChanged(Message&
m)
at
DevComponents.DotNetBar.Office2007RibbonForm.WndProc(Message & m)
When the error page pops up, it is this:
I can't think of anything I did before this happened, which is very frustrating. The last thing I did was this:
Add Button on Ribbon Control
Double-Clicked the button to add code
Realized I forgot to name the button, so removed the event code
clicked back on the form tab and BAM. Error.
I tried the following to fix:
Went back and did an undo on the code (re-added the event for that button). But didn't help.
Edited the Designer.vb file to remove that button entirely. Still didn't help.
I thought about pasting my designer code here... I will if that makes sense, but it is so huge I wasn't sure if that was worthwhile. Maybe the above error makes sense to someone besides me???
**** EDIT: Forgot to mention the application runs fine. Just can't edit the form anymore.
OK. I found it. For some reason the form duplicated the style on the ribbon control. Even though the error didn't seem like that one.
FYI - I just kept commenting out stuff in the designer and then trying to launch the form until the error went away. When I finally got to the ribboncontrol, I saw that there were 2 statements:
'Me.RibbonControl1.Office2007ColorTable = DevComponents.DotNetBar.Rendering.eOffice2007ColorScheme.Silver
and
Me.RibbonControl1.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled
As you can see, I commented out the first one and everything worked.

Access 2007 "Return without Gosub" after i deleted a button

SO something strange happened, I was cleaning up my database and deleted a button that honestly just closed the current form and opened a different datasheet. now whenever i try to select a field or do anything I get things like The LinkMasterFields property setting has produced this error: 'Return without GoSub' ...i Dont really understand how this could all of a sudden happen
thanks for any input it would be greatly appreciated
Problem Solved, Allthough i did delete the button the error was caused when i didnt delete the click event associated with the button. It is strange i think because i have most certainly deleted buttons before and didnt need to delete there click event scripts and everything still worked fine.

Changing form name causes error message "Error accessing the system registry"

I am programming the On_Click method for the button labeled "View" in the first printscreen below. The method will load a form with data corresponding with the specific address id in the row containing the "View" button. This code worked perfectly when pointing to a target form called "Addresses". However, when I decided to rename the form "Address", I started receiving the following error message when clicking on the view button:
I did some research on the web about this error message, which lead me to try to delete any outdated references in the VBA editor. But when I clicked on Tools-->References in the VBA editor, I got the following error message:
It seems that MS Access' entries in the system registry might have been corrupted. But I am not certain of this because the documentation of this on the web is sparse and inconsistent.
Here is a link to the database on a file sharing site: http://jmp.sh/b/9Uyx6J2YzWbs8zPq2h6g
If the problem is in the database, you can recreate the problem by opening the form "Main" and clicking on the button "View" for the record shown in the printscreen above, or for other records.
Can anyone show me how to get past this error message?
my advices?
You could rename your Forms!....SourceObject to "Address" instead of "Addresses"
You could copy/paste the form, delete the original, and retry
You could install a decent debugging tool like MZ-Tools for VBA, that will help you manage your errors. Check the details here
EDIT: I used to get similar bugs years ago, when I was writing specific form event procedures. As we decided to switch to a model where forms did not need to be debbuged anymore (check this here), we stopped getting this kind of message. And I think I forgot the trick we used to solve this kind of error. If I were you:
I'd try to open another access database and import all objects ...
I'd put aside/cancel the faulty onClick procedure
And I'd install MZ Tools because otherwise VBA debugging is a nightmare ...
Since access was not liking the command button in each record of the continuous form, I choose to put the view button's logic in the on click event of a text box in each row, which I configured as enabled but locked. This produces a separate link from each record of the continuous form to a unique detail page with more of the chosen record's data.
This solution works perfectly, and is enabling me to move on with my other coding.
However, it would be nice if someone else were able to show how to get the command button solution to work.