Variable does not exist but compile works, runtime fails [closed] - vba

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have inherited a bunch of Access projects. I found a very strange issue where some form code accesses a variable that does not exist. The compile works fine, intellisense will auto complete the variable but at runtime I get an error 2465, can't find the field 'xxx' referred to in your expression.
The field most certainly does not exist, there is no variable by that name.
Any ideas why the compiler is not finding the issue?
I think it may have something to do with the query to fill the form. I think it did have the column XXX at some point, then it was removed. The compile still works but the run does not. I'm not sure.
There is no code with this question because the code is not at fault. If you read the accepted answer below its a 'feature' of Access that the VBA compiler uses the auto generated column names from a record source as variable names, modifying the query breaks this linkage.

You don't mention if the var comes up with you type me + "dot" in the given form.
This would reveal important information.
You can also type in the variable name (it it is not a me.dot var) and then hit shift f2, and that should/can jump you to the location of the variable.
However, if this is a me.dot value? then open the form in design mode. Display property sheet, data tab.
Now select and CUT out the forms datasource to your paste buffer. You now must TAB out of the datasource. Now, tab back in, re-paste in the forms datasource, and AGAIN tab out. This forces access to re-generate the "me." members for the form. So, over time it is possible to delete columns and controls on that form, but the "members" are thus no re-generated until such time you do above.
so, the missing detail here is this a me.dot intel-sense, or is this some global var defined in some code module? As noted, if this is a not a me.dot member of a form, then click on that var, and try shift-f2 and see if that finds the variable.
Of course in the vba editor, you can also do a ctrl-f and search the GLOBAL application for all and any occurrences of that variable - and thus such a search of all code would and could again find the origin of that variable.

Related

Intellij Live Template Dynamic Text

I'm trying to create a "dynamic" Live Template for PyCharm and am hitting a road block (I'm able to create simple templates with variable insertion, no problem). I'm beginning to believe that what I'm trying to accomplish may not be possible. I'm not tied to Groovy Script, but it looks to be the most promising alternative to what I'm trying to accomplish. I'm not able to provide a minimal, reproducible example beyond a simple description. Here's what I'm trying to accomplish:
Whatever is typed after hitting TAB and before hitting Enter is passed to the template, formatted and written back to the Editor. My goal is to have the resulting string be a specified length, but that's less important for the time being. It's really more about how to get keyboard input to the template and back out again.
For example:
"blk" TAB "Hello world" Enter becomes # ==================== Hello world ====================
Is this possible with Live Templates?
EDIT: To be clear, the question here is on how to reformat the typed input and return the formatted input to the output of the template. For example, using the above -- have the resulting "Hello world" line always be 80 characters long.
EDIT2: converting previous comment to an answer to close the loop on this question. Happy to reopen if new information comes to light.
Yes, it should be possible with such a template:
# ==================== $MY_TEXT$ ====================
Where $MY_TEXT$ is just an empty custom user template variable.
I have confirmed with Jet Brains that the thing I'm specifically trying to accomplish--dynamically formatting typed input to a live template--is not possible within the current IDE (as of version 2020.3).
Instead, they suggest it will require a custom plugin with specific features related to com.intellij.codeInsight.template.postfix.templates.PostfixTemplate.

MS Access VBA editor activity affects running program variables

MS Access 2016 running on Windows 10.
I am debugging VBA changes to a MS Access application and am seeing some unexpected interactions between the VBA editor and running code. The steps are basically:
Open the application, which opens startup form.
The startup form_load instantiates an object used by other forms the user may subsequently open.
Open the VBA editor
Using the VBA editor, select a line in any code module and the instantiated objects are set to nothing.
An error is thrown when the other forms using the object are opened.
So basically, the VBA editor action has set the objects to nothing. I have added instrumenting code to confirm this.
Has anyone seen the behavior? Does anyone have thoughts about what may be happening and causing this?
Thanks in advance...
Additional information:
The code instantiating the object in the Form_Load method is:
Set musrInfo = New usrInfo
Where usrInfo is a class module containing user information.
Also, there is no problem with earlier versions of this - I have never experienced the described problem with any other MSA VBA application. The compiled version of this particular MSA file is a bit bigger than 20MB, with little in the way of data tables - only a few parameters, etc. - and more than 13MB in forms, reports, etc.
I hope this helps... Lindsay
And there's more...
- I tried this .accdb file on another PC with Win7/MSA2010 and this
behavior did not occur.
- I then tried it in a different folder on the original PC and it
did not occur.
Maybe these findings will allow a path forward, but I still wonder why this would ever happen - why would the folder choice make any difference?
This is usual behavior.
When making changes using the VBA editor, it may recompile the VB project behind your database. This can be the whole project, or parts of it, depending on the exact change.
Recompiles will clear any variables.
You can change this behaviour, by going to Tools -> Options, under the General tab. See the following screenshot.
However, even with Compile On Demand off, you will have to trigger a recompile for most changes, clearing any set variables.
For classes that need a single instance to be publicly available as long as the database is open, I recommend setting the VB_PredeclaredID to true. That will instantiate the object as soon as the database opens, or the code recompiles. See here how.

setting Visual Studio to help me better document my code [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
What I am trying to do is setup Visual Studio 2017 Enterprise to have it help me keep track of my code architecture better. I am running on Windows 8.1 if that makes any difference. An example will (hopefully) demonstrate what I mean:
If I want to use the sine function, Visual Studio insists that I pre-pend Math. in front of it: Rise = Math.sin(Angle)
What I want to do is have the same behavior for libraries that I have created. I have created a class called K2Math (called out as Public Class K2Math) and in it are functions like: Public Shared Function CheckForCollinear( . . . ) as Boolean. I have bundled it up into a separate DLL.
In my caller code, in the project references I have a reference to K2Math.DLL. As the functions are Public Shared, I don't have to use 'New K2Math' setup call like I would with a more conventional DLL. However, in the caller program I can use the CheckForCollinear function without having to pre-pend K2Math. I can also call it using K2Math.CheckForCollinear and the compiler doesn't complain.
What I would like the compiler to do is complain and force me to pre-pend the K2Math. This would help to make it obvious to me or whoever is reading my code how the code is architected and segregated.
But I can't seem to figure out how to do that. Also, I haven't figured out how to succinctly pose the question to do a proper Google search.
If I am being unclear, please so note that and I'll try to clear things up.
Create a Library lets say CustomizedMathLibrary
In that create a class K2Math. WRAP in a NAME SPACE (This is important)
Build and Use It by Importing name space in your code.

How to link a measure variable in a supervision to a VBA code?

I'm currently in an Internship where i'm supposed to bring some modifications and upgrades to an already functioning SCADA in Pcvue.
One of my mission is to be able to modify an already existing measure variable directly into the supervision while it's active.
I managed to code a working inputBox via VBA but the problem i'm left with is that i don't know how to assign the number i write directly to the already existing measure variable.
Do you guys have any idea how to code this?
You dont need any vba code and inputbox to enter a value. Use simply a standard Send animation with an internal variable.

How to get Motherboard name in VB.net?

My program needs an upgrade and I was looking for the Motherboard name and Maker(Developer).
And here's the problem there is WMI what is offered almost everywhere, and it lines up with
Console.Writeline, what i want to do is to get the Label to show the same thing what i get with WMI.
The solution what was offered by Thorster Dittmar, did not work, I tried that at the beginning:
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
It's a bit hard to understand your question, but what I read from it is:
You want to display information you get via WMI in a Label, but the output so far is on the Console?
Well, use the following steps:
Create a Windows Forms application
Place Label on form
Copy code that accesses WMI to Form_Load event handler
Instead of Console.WriteLine(xyz) do label1.Text = xyz
That should be it. If that doesn't answer your question, please edit your question so it becomes clearer what you want.