Debug function altough macros disabled - vba

I was given a template for report (.dotm) with alot of vba code behind that gets data from a mssql database and writes the data at some bookmarks.
Unfortunately, the code has an error and I have to fix it.
Since I have never done vba before, I'm a bit lost.
There is a function with 2 parameters that does everything.
Can you tell me how I can debug this function?
I have set a breakpoint to the first line but how can I tell word(?) to execute the function?
My first approach was to add a button and set the onclick event to this function. But unfortunately macros are disabled by our policy and this doesn't work :(
Can you please help me out how I can get inside this function?

How can anyone expect the code in the template to work if macros are disabled?
Try ALT+F11 to get into the VBA environment and show the code. Put the cursor in the code you want to debug and press F8 to step into it or F5 to run it to any breakpoint.. If the code you want to debug has parameters, you have to write a dummy Sub to call the function with test-parameters.
Also, see sams comment about the trust center. Maybe you can change the settings yourself to allow macros.

Related

How to step through VBA code behind a form? VBA error 2186: This property isn't available in Design view

I can run a macro under forms, but when I look at the code behind the form, I am not able to step through it all.
I hit the line
Dat = [Forms]![frmMenu]![dtmDate]
and get the error:
Is there a way to resolve this so I can continue to test each step of the macro?
I opened the code with ALT + F11.
I am trying to pinpoint the queries which cause the macro to take so long to run.
You can't hit f5 to run + debug code in a form. You can do this for a standard code module, but not for what we call a class module.
If you wish to debug/step code in a form? Launch the form (normal view). Then go to the code behind, say a button click, and now you can set a break-point.
So, single step, or debug of forms code requires you FIRST load the form as normal. (you can't thus use f5 to run such code). But, you CAN debug as per above.

Vba Macro works but not starting in main()

Have created a Macro - multiple subs, functions and forms for Solidworks.
I'm sure the code is dubious but it works when I force it to start in main()
When I add a button in Solidworks to start the macro it defaults to a different sub, which appears to be alphabetical, I get a similar behaviour starting the macro from the editor.
It appears all the subs listed are the ones with no arguments passed in.
Could anyone please guide me on why this happens? I'm sure I could frig a way around by renaming the subs, but don't realy want to.
It appears I was to impatient, again!
When adding the macro button in Solidworks you are given the choice of choosing the sub to run ... as Method

How to call an afterupdate event from another module/control event (MS ACCESS VBA)

I have been using Microsoft access for a while however i seem to be having some difficulty with a single line of code. i know it is possible to trigger a form controls event from another module or event as i have done before in VBA for excel, however when i try to do this in MS Access it gives me a runtime error
any and all help would be appreciated in this matter as I'm sure there is probably something very basic that I'm missing here.
Please see below code for easy reference.
Forms("Insert_Data_Others").CMBVoy_ID_Oths.AfterUpdate
Call CMBVoy_ID_Oths_AfterUpdate
Make sure procedure is not declared as Private.
Use underscore in place of the last period.
Forms("Insert_Data_Others").CMBVoy_ID_Oths_AfterUpdate
or this version which will show the event in intellisense tips.
Form_Insert_Data_Others.CMBVoy_ID_Oths_AfterUpdate

What is the SQL code for suppressing the pop up warning boxes from displaying in a MS Access Query?

So I have a simple delete all query that is embedded in a macro. When I click the macro it always ask, are you sure you want to delete x rows? All I need is the SQL code to suppress the message, NOT THE VBA CODE. Google results only pull the vba code and I need the SQL code. Any help is highly appreciated! The code is below:
DELETE *
FROM [New History];
Very simple, just need to know what the SQL code for suppressing warnings are, not the DoCmd.SetWarnings False method used to suppress it in VBA. Again, any help is highly appreciated!
SQL is for data manipulation, not for any UI related tasks, such as showing/hiding messages.
There's no such SQL code.
However, when using an embedded macro, there is the SetWarnings action, under System Command, only visible if Show All Actions has been clicked.
Nevermind, I solved the issue myself. The SetWarning can be applied in the macro you just have to set wherever the file is located at to be a Trusted Location. Then it worked.

New to Access How to run VBA code that doesn't have Sub?

Hi, I'm new to Access and I have a quick question.
I have a code that does not have 'sub'. And I was wondering how can I execute my code when I don't see any on Macro window? (Refer to the image attached)
My code start with function and declaration of variables!
It's very straight forward question but please comment below for any clarification if needed!
For you to be able to run a function with the press of a button for example, you must:
a) Put the function in a standard module, within the vba editor. Move the code to a new module and then call the function from a macro.
Or
b) Run the function from within an event vba sub like the click of button.
For both a sub, and a function in a code module, you can normally place the cursor in the sub/function and hit F5, and the code will run.
The above works for both a sub and function.
However, WHEN the sub/function has a parameter(s), then the F5 option will not work. In your screen shot the given function requires a parameter, so the long standing F5 to run such code as per above will not work. What occurs in this case is the macro prompt will launch as you point out.
Two suggestions:
Whack ctrl-g and your cursor should now be in the debug window, you can type in the name of the function (or sub) and SUPPLY the parameter.
Eg:
Test9999 "my first prameter"
The other means is to write a test code stub that passes the parmaters like this:
Public Sub RunMyFunction()
Test8888 "my paramter"
End Sub
And thus you can now hit F5. So you don’t need to run the code from a form or a button as suggested here. However, the instant the sub/function has a parameter(s), then you lose the F5 to run the code from the VBA IDE. You have to write a code stub, or as noted enter the function name + supply the required parameters of the correct type in the debug window to run the function.
However, to be fair, you can build a test form, and place code behind a button, but your question was in the context of the IDE and use of F5 to run such code.