Modules & VBA :: Running A Macro From Another Form
Jan 31, 2014
I have 2 forms and a macro in Form1 which runs throught every record to update the records, however.I would like to run this macro from the main form (Form2)
I can manually stop the AutoExec macro from running by holding down the shift button - how do you do it by VBA? I'm opening the db from Excel, and I don't want the Switchboard to display ...
I've got a Macro that runs well over 100 queries as well as sub-macros. I'd like to know what query the Macro is running. My best solution so far was to create a bunch of forms that open and close with the name of each query, but that's kind of sloppy. I don't think I can use the msgbox because it prompts me to press 'OK' to continue. Any thoughts?
I was hoping that someone could tell me if it is possible to run an Excel macro from an Access database. I am importing 3 Excel worksheets into Access and this macro needs to be run on all 3 evertime that this file is imported by the user (twice a week). If this can be done could someone please tell me how ??
set warnings to warning on: NO and runCode to Function Name: cmdImport_Click()
where cmdImport_Click() is a Private Sub in a module within the same database.
when i try to run the macro i get an error that stated "the expression you entered has a function name that MS Access can't find."
but if i open the module called ImportMSExcelFile and set my cursor on the Private Sub cmdImport_Click() and select the green arrow to run the procedure it runs fine.
I have a MS Access append query that updates a table from a linked Excel spreadsheet. Im trying to automate the running of the query during the night.
Ive tried a couple of ways to schedule the task with Windows Task Scheduler, although each time, it appears to start the job, but then just hang (task never completes, doesnt run the query or macro and when I log back into Windows, the msaccess.exe process is running).
Methods Ive used are:
- command line with /x macroname
- vbs script which runs the query / macro
Code: 'Read from a Microsoft ACCESS database Option Explicit dim oaccess 'execute another Access macro set oaccess = createobject("access.application") oaccess.opencurrentdatabase "H:Database.mdb" oaccess.docmd.setwarnings false oaccess.DoCmd.RunMacro "Macro1" oaccess.docmd.setwarnings true oaccess.closecurrentdatabase oaccess.quit set oaccess=nothing WScript.Quit(0)
- .bat file which just has the command line in it.They all run fine when I am logged in, although it seems to hang when I am logged off the network. I have the correct permissions as Ive scheduled a Excel macro to run and its fine.
I have 3 different "buttons" on my form that run individual update queries. I know these update queries are running correctly. Decided to make a macro that will allow me to run all these queries by clicking one macro button.
My question is: Is there some way to stop the pop up msg that advises I am about to run an update query and the next pop up msg that informs me of how many rows I am going to update?
These pop up boxes are starting to drive me crazy when I run the macro.
I am trying to write a more complex macro that will start another macro at a preset time, however I am getting stopped at the first hurdle - getting a macro to run another macro.
Here is the code i am using at the moment, all I want to do currently is click the first button, then get the second macro to execute. But no luck, getting error 2157 "cannot find the procedure"
I have a form with various text, date and combo controls. There is a button at the button that runs a macro (Close NB) at the bottom. What I'm trying to do is bring up a msgbox if certain fields are blank and not run the macro. I only want the macro to run if all the fields specified have data in them.
The fields are : cmb_cliname cmb_disease cmb_projectType cmb_ProposalStatus
The on click code is: If (Me.cmb_cliname Is Null) Then MsgBox "Please fill in the relevant details", ElseIf (Me.cmb_Disease Is Null) Then MsgBox "Please fill in the relevant details"
i want to be able to create an On Click Event when pushing a command button that will run an Update query to update a record and after it has been updated that specific record will pop up on a Form and be displayed. i know a different way is to run the Update query and then have it displayed in a Select query but i want it to be displayed on a Form instead. is it possible?
how to get macro properties using vba? I've attempted something similar to the below to try and divine macro properties:
Code: Sub MacroDiscovery() Dim mcr As AccessObject Dim prop As AccessObjectProperty For Each mcr In CurrentProject.AllMacros Debug.Print mcr.Name For Each prop In mcr.Properties Debug.Print prop.Name Debug.Print prop.Value Next Next End Sub
Nothing comes up except the macro names. In my database, I have an AutoExec macro that I have manually added a description to; "This macro auto-executes when the database is opened by virtue of it's name." I can view the description by right-clicking on the macro and choosing 'Object Properties'.
Background:I am attempting to make a universal Access Database documenter for the many, many homemade databases on our network. I'm only interested in certain pieces of information and I would like to make a report to view the information how I want to view it. Thus, I don't care for the built-in documenter--I want to do it my way.
I have inserted a function via a module at the beginning of a Macro using the RunCode action:
Function Msgbox_Yes_No() Dim Response As Integer Response = MsgBox(prompt:="Select 'Yes' or 'No'.", Buttons:=vbYesNo) If Response <> vbYes Then End If End Function
However, it doesnt stop the macro from continuing on its way to delete a load of records if the user chooses no.
I'm working in 2003 (still) and have a macro to print the selected form the user has on their screen. I need this same macro to also print a PDF in a particular network folder or just exit if the PDF doesn't exist. I've tried RunSQL with "PrintDoc [Link2PDF]" as the argument. I've tried RunApp with "Acro Rd32.exe /t [Link2PDF]" as the argument but neither one works. The RunApp line will open the Adobe reader but nothing more.
I would like to have a macro run at a set time each day. I hoped to use .ontime but apparently that doesn't exist in access.
The macro must run at 10:00am each day, the db will be open from 8:30am until 16:30pm so no problem from that point of view +/- a few mins when the staff arrive.
I have just installed the windows version of Access 2010 on OSX Mountain Lion using a program called Crossover which works very similarly to WINE. I have found that Access will install fine except for VBA form modules and BAS modules, although there seems to be no indication that they did not install as the entire install progresses fine.
I've put together an invoicing program that was created in Access 2010 in Windows but have transferred it over to Access 2010 installed on OSX. It contains a number of forms with code but when I go to VBE, form code modules are not visible. When I try to view the code for a form I get the following error message: "Microsoft Access failed to create the Visual Basic module. If your database is on a network drive, check your network connection, then try again". I was able to insert a BAS module and create a rudimentary VBA subroutine which ran without error so it does seem able to interpret VBA as per normal.
I have an open form with buttons to open other forms and use an If statement to position them an example is below.
Code: Private Sub Command31_Click() DoCmd.OpenForm "Opener", acNormal If Me.Frame54 = 1 Then DoCmd.MoveSize 2500, 1000 ElseIf Me.Frame54 = 2 Then DoCmd.MoveSize 25500, 1000 End If End Sub
This works perfectly, however I need to put similar code as a line in a macro and cannot seem to link it.
Code: Public Function totalmove() If Forms.Scan_Data.Frame54 = 1 Then DoCmd.MoveSize 2500, 1000 ElseIf Forms.Scan_Data.Frame54 = 2 Then DoCmd.MoveSize 24000, 1000 End If End Function
I get Error 438 object doesn't support this property or method...
I have two tables in my Access database, their fields are exactly the same (for now). One table is called Uncheched. The other one is called Checked. So what is need is a macro that takes selected records in table Unchecked and copies them to the end of table Checked. Actually CUTS from Unchecked and PASTES to the end of Checked table.
Sub MoveRecords() DoCmd.RunCommand acCmdCut DoCmd.OpenTable "tblChecked", acNormal, acEdit DoCmd.GoToRecord , , acLast DoCmd.RunCommand acCmdPaste End Sub
I have a table it contains a list of opening and closing values along with a date and a couple control fields. What I would like to do is duplicate a few fields from records that meet a criteria onto the same table. After that is done there will be a few updates on the new records. Looking at it, it would be: 'duplicate' where field2 <> 0 and field5 = No and field6 = Yes. All other fields on the newly created records would be their default values.
I'm trying to run an sql update query (in VBA) to update values in a table, from calculated field values in a subform (using a query as a record source).
Is this possible , and if so, can I call the subroutine from the parent form, and what would be the correct syntax for the VBA sql string (i'm guessing it would be a docmd.runSQL sqlstringname )??
I have determined the solution to my problem lies outside of normal SQL queries and I need to create a UDF.
Here is the problem. I need to create a running total based on the sum of two fields [PTS_ISSUED] & [PTS_REDUCED] with one restriction. The total can never be less than 0. If it is less than zero, the totals reset with [PTS_ISSUED] as the new starting point.
I've attached an excel spreadsheet. Column"C" contains the formula logic I am trying to replicate into access.
I will be honest, writing the UDF is beyond my current knowledge but once I see it I am able to understand it and implement it.
I believe the solution needs to store the running total into a variable, make the necessary comparisons and determine if its okay to add the [PTS_ISSUED and [PTS_REDUCED] to the stored total of the previous calculations then advance. I just have no clue in how to go about writing it.
This calculation needs to be presented in Access because the results will drive several other functions within the database.
I created a database that uses the "lngEmpName " number to give user permissions , what I need is to be able to disable the running of the database (or main form)and show an error message using vba if I have not logged in for around two weeks is this possible ? if so how and even better a demo would be fantastic.