Any idea why this would be happening? I don't get any error inside the Class_Initialize sub, it just jumps straight to the Class_Terminate sub and the object I assign the class to ends up being Nothing.
I don't have Access 2000. See whether it has an error trapping option "Break in Class Module". For Access 2003, that option can be found from the VB editor's main menu: choose Tools->Options, then select the "General" tab on the Options dialog. The radio buttons for the Error Trapping choices are located on the middle right of the dialog.
It's not clear to me whether your class module is throwing an error silently. That option should (I hope) help you expose the error ... if there is one.
If that effort is not useful, think I would next set a break point on the first executable line in Class_Initialize, and then step through the code one line at a time with the F8 key. You can see which lines are executed, and at any time while you're in break mode you can inspect the values of variables by printing them to the Immediate Window ... with Debug.Print YourVariable or the shorter ? YourVariable
A slicker way to monitor your variables is to open the Watches window (from the menu, View->Watch Window), then add variable to it (Debug->Add Watch).
Finally, if those efforts don't lead you to a solution, create a stripped down version of your class module with only the bare minimum code needed to reproduce the problem. Add that code to your question, and also include enough of the calling code to show us how you're attempting to create and use the object instance.
Related
Having this strange behaviour in my Access DB since today. If I try to run code in VBA (i.e. F5) a box comes up and asked to select a macro to run. Never had this problem before as I just want it to run the code I did. Tried to find a solution but no success.
I happens for all my code... like Public Function or Private Sub...
For example I created this code. When I execute it by clicking the button it works but if I run in VBA with F5 it always asks for the macro...
Public Sub Command18_Click()
MsgBox ("Hello")
End Sub
This occurs if you try to hit f5 and run code in a form.
While you can hit f5 for a regular plain jane code in a code module, if you try this for form code, then f5 will pop that macro prompt.
Also, if by accident (or by intent) created a class module? Then again, you see that prompt.
So, for a form code module, or a class code module?
Such code can be started by hitting f5, since you need to create an "instance" of that class before it can be run.
And, a form's code module also is considered a class module - an instance (in this case the form has to be open) must be created first. So, in the case of form's code module, you can set break-point in that code to debug, but you can't hit f5 in such code modules, or inside of class modules - since an "instance" of that object has to be created first, and hitting f5 is not able nor capable of knowing which or even where such code exists to create the instance of that class code module (of which even form's code modules are also this case).
The HUGE giveaway here is that in your comments you note some click() event. Well, then that means your working with code inside of a form's code module - and f5 can't be used to start such code - it is still a class module, and an instance of that code module has to be created first.
So, if I create a class code module like this:
then
Option Compare Database
Option Explicit
Sub TestMsg()
MsgBox "hello"
End Sub
Now, if I hit f5 in above sub, the macro prompt appears!!!!
I would have to create a plain jane regular code module, and say type in this:
Sub TestFun55()
Dim MyClass As New Class1
MyClass.TestMsg
End Sub
So, I can hit f5 in above.
And the SAME goes for code inside of a form's module. You can't hit f5 in that form's code module (which is considered a class code module).
I have a question about the Macro Design in a table for a "After Update" function. In one database that one of my past employees built the "SetField" value as a function call. One of the functions it calls is called GetUserNAme() it is buried in another bas_AuditLog macro, but in a DB that I am building, it doesn't work, even though I thought I had all of the information copied and correct. I have attached an image here that might show my issue. Notice the red exclamation mark.
Image of Macro Builder with error
Perhaps one of you smart people can help me look at an area that in my DB that may have the missing link.
Thanks.
Ok, so in the other (working) applcaiton, there is a going to be a public function called GetUserName(), and it is a VBA function.
So, in that working applcation, you can hit ctrl-g (get to debug window), and then type in GetUserName and then hit shift f2. Your code editor should now jump to that VBA function. You need to copy that code to your new applcation (place it in a plane jane standard code module (not a forms module, and not a class module). and it might very well also use a api call.
So, when you copy over that code. Test and make sure the VBA code works. In most cases in the access debug window, you can type in this:
? GetUserName()
And it should spit out the current windows user name. (or whatever the code supposed to do). So, get the VBA function working, and once you do, then your data macro should now also work.
I seem to be having a problem that looks an awful lot like it could be a bug in MS Access. I have a form which enumerates all the rows in a table and lets you edit them in a subform. Upon clicking save in the subform (standard save button converted to VBA), I want to update the list of records in the main form. I seem to have done just that with this code:
Parent!List0.Requery
Parent!List0.Refresh
Parent!List0.SetFocus
However, the list of records only seems to update with the changes upon clicking somewhere in the box, giving it focus.
Has anyone run across this, or does anyone have any suggestions as to how to solve this?
I cannot reproduce the issue, at least not in Access 2010. I had to comment out the Parent!List0.Refresh statement because that was causing a run-time error ("Object doesn't support this property or method"), but once I did that the List Box was correctly updated as soon as I clicked the button on the subform. There must be something else at play here. Could you possibly have error handling in place that is "swallowing" the run-time error I received?
Set a breakpoint at the beginning of the Button_Click() code and follow it through. Perhaps your code is not executing the way you think it is.
Get rid of the Refresh statement, it's not necessary. You'll probably get a run-time error right there because that property isn't supported.
How do I create a variable with a scope? It's just giving me a default which I do not want, and I'm unsure how to change. This should be simple, and a Google search leads me to believe this is quite a common problem but with no easy solutions.
imgur: http://imgur.com/uxlRf
click on new variable button, add variable name and then click on Move Variable Button right next to add variable. and from there select Executable , to which you want to set a scope to. Hope this helps.
Note: Scope of the variable is set based on the container you have focus before clicking the new variable button. Though BIDS Helper can help you change the scope of the variable very easily that’s the 6th button provided by BIDS Helper on top of the variable pane.
Found the above answer, not very helpful way of doing things.
As someone noted, this changes with 2012. I just got bit by that and note that the 2012 documentation did NOT get updated. It still says variables are scoped to what you have selected which is NOT true. But when you're on the variables window, note the 2nd from the left icon at the top - this is the "Move Variable" button that works quite nicely to allow you to move the scope of the selected variable. BiXpress also has similar function but it's buggy in that it won't pick up OnPostExecute scope making their version very limited.
We can change the scope of the variable in 2008 BIDS.PFB the steps I did for changing the scope of the variable from the package level to the task/container level.
1)Right click on the package.dtsx file from the Solution explorer and click on the "View code"
2)Search for the variable for which you wanted to change the scope. Copy the XML code related to that variable.
3)Search for the control for which you wanted to use this variable and copy the xml code after completion of any tag(Many tags are related to a task/container).
4)Remove the origial copied code.
5)Save this file
6)Open the package and the scope of the variable would have been changed
I am not sure If it impacts the package or not, but it worked for me.
Kindly let me know If it will impact the package or not if any one knows
How about:
View code of *.dtsx package
Change DTS:ObjectName for desired one.
Will this lead to any issues? At the moment it seems ok but i can't run package yet to check this.
Well thats the way BIDS has been designed. You create on the control flow element on which you want to create the variable. And if you want to create the variable on the package level, you click on an empty space on the control flow pane. Thats the only way to assign scopes for variables using BIDS. Havent looked at the BIDS Helper, but BIDS itself is capable enough of doing such things.
Got a weird problem. I was debugging some code for a form and everything was working as intended for the most part when suddenly I began to get a "Method or Data Member Not Found" for every event of my form. It's like my form suddenly does not recognize any of my controls or events. I have all of my methods properly closed and did not rename any controls.
Any ideas on what would be the root of "Method or Data Member Not Found" for every single control with an event?
Thanks
Importing into a fresh database as talbright suggested gave me more descriptive error messages.
A fresh import, compact&repair, and renaming of appropriate control fixed the problem from occuring. As Remou suggested, regular maintenance can help prevent these sorts of problems.
edit for future readers: This problem occurred while using a shared front end file. So don't do that if possible.
I've found that any MISSING: reference can make the simplest of code fail.
Check in the visual basic window
Menu Tools -> References
look down the checked refences to see if any are MISSING
I just fixed the same error by renaming text and combo boxes something not so close to a concatenated Table & Field string. Actually just prepended those names with "tbx" and "cbx".