Modules & VBA :: Running SQL From A Subroutine In A Subform?
Feb 23, 2015
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 )??
View Replies
ADVERTISEMENT
May 17, 2014
I have a database which needs to be updated everyday. So I decided to make a subroutine to perform the update steps just by clicking on a button.
The problem is that I can run all the steps except one! At the end of the steps, there is a function/module that must be run to calculate and complete the job.
How I can run a function in a vba macro. This is my code:
Private Sub cmdUpdateDatabase_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "qry1AddNewStockSymbols"
DoCmd.OpenQuery "qry2AddDailyPrice"
DoCmd.OpenQuery "qry3UpdateStockDailyPrice"
DoCmd.OpenQuery "qry4AddOverallStockValue"
DoCmd.OpenQuery "qry5AllSymbolsActiveDaysTractions"
DoCmd.OpenQuery "qry6SortToCalculateDailyRemainedStock"
DoCmd.SetWarnings True
End Sub
Module name is: CalculateDailyRemainedStock
View 3 Replies
View Related
Jan 14, 2015
Imagine I have two subrountines:
Code:
Private Sub DoSomething1()
[Do Something]
End Sub
Private Sub DoSomething2()
[Do Something]
End Sub
And this Declaration:
Code:
Dim str As String
str = 1
Is it possible to refer to/call one of these subroutines using something like this:
Code:
("DoSomething" & str)
View 1 Replies
View Related
Jan 30, 2015
Sometimes I find the 'need' to exit a subroutine from within a control 'loop' e.g. if.. then..else with... while... et al.
I suspect this is 'bad form' but is there any 'cost' in doing this?
There presumably will be if objects have been set and are not reset to Nothing. In this case it presumably is not a problem resetting to Nothing outside a With.. - what about inside a with..??
View 10 Replies
View Related
Oct 25, 2004
I want to call a selfdefined subroutine "update()" in several reports. But whenever I try this, Access gives me an Error 2465. The Report is selected dynamically by the user and should adapt itself to other settings made by the user. Can anybody help me how to do this? Thanks.
View 4 Replies
View Related
Dec 15, 2005
Is there anyway to have a subroutine be called when a form is brought up? meaning, as soon as the user opens the form, stuff happens without them doing anything besides opening the form.
View 1 Replies
View Related
Jul 7, 2004
Hi all.
I have a form that opens up another form when you click on a button. The button does more than just open the form, it does other checks. I want to wait until the opened form is closed to continue with the subroutine. Is this even possible in VBA? I was wondering if there was a frmFormName.IsOpen or some kind of flag that would tell me if a form is open or not. Any help would be greatly appreciated. Thanks in advance.
Sub open
Checks things
Checks things
checks things
Opens form(frmDetails)
Wait for form to close (THING I DON'T KNOW HOW TO DO IF POSSIBLE)
Checks things
Checks things
end sub
View 2 Replies
View Related
Sep 25, 2014
Is there a way to add a field to a subform that preforms a net value calculation on all the records in that subform?
Fields:
Record ID ItemAmt PaidAmt Need a Net field here? (not part of form; description only)
1 500.00 100.00 400.00 500.00-100.00
2 500.00 50.00 350.00 400.00-50.00
The Item Amt is referring to the main form and should be the same amt.I need the Net field to act as a running balance.
View 11 Replies
View Related
Sep 20, 2012
I have only 1 table that im working with I simply want to have a form that runs a search on one of the fields and returns the results.
This is what I have:
1 Table
ID : Autonumber
ProblemType : Text
Technician : Text
I want to create a form that has a main form with a text field that i can input a string of text and run a search on the problemtype field. And return all the results in the subform with based on keyword that was inputed in the form above. I want the results to display Problem type and Technician fields. What is the best what to do this?
View 1 Replies
View Related
Jun 21, 2013
I am trying to call a subroutine from a VBA routine to append a record to an existing table. Below is the code for opening my recordsets for reading followed by the code creating my table to append to:
Public Sub UpdateLotsizes()
Dim curDatabase As DAO.Database
Dim ProdPlanDB As DAO.Database
Dim rstQryLot As DAO.Recordset
Dim rstInvLoc As DAO.Recordset
Set curDatabase = CurrentDb
[Code] ....
To call my subroutine, I simply put in the code:
ExceptionReportAddRecord
And this is the code of the subroutine:
Public Sub ExceptionReportAddRecord()
Dim rstExcRpt As Recordset
Set rstExcRpt = curDatabase.OpenRecordset("tblExceptionReport")
With rstExcRpt
.AddNew
.Fields("item_no").Value = txtItemNumber
[Code] .....
I am receiving "Run-time error 434: Object required" at the line I marked with ...
View 4 Replies
View Related
May 5, 2014
I have a form that has five subforms on it. On Open all the subforms are unbound (so i can prevent the queries from running before the On Open event to speed up). Then i can enter my criteria for all five subforms in txtbox and click run. After I establish the source object for the subforms, i cannot establish the controlsource for several text boxes that pull the data from the subform, i get #Name?. her is a sample from the on click event... the top links the unbound subform and the bottom should then link a control in the subform to a control on the main form.
Me.Child167.SourceObject = "query.RP Sum Fuelman F1"
Me.Text71.ControlSource = "=[RP Sum Fuelman F1 Subform]![cntRecords]"
View 1 Replies
View Related
Jan 7, 2013
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.
View 2 Replies
View Related
Aug 5, 2015
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.
View 8 Replies
View Related
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 have tried
docmd.openform "Form1"
Run Macro
but it doesnt work
View 4 Replies
View Related
Jul 23, 2015
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.
View 4 Replies
View Related
Apr 1, 2014
I am running delete and update queries using docmd.runsql. I am finding that particularly after the update query is ran the record is locked and other field in that record can not be updated via a form without a warning saying another user has made changes to the record. To be more specific -- I have a vendor table which has fields vendorname, vendorstreet, vendorcity, vendoraddress. A form is used to place a street address to the vendorname. onexit of the street textbox an update query is ran using DoCmd.RunSql updateing the vendoraddress field to an 'X'. When I put the city in and then close the form this is when the error occurs stating that another user has made changes to the record. My thought is that the update query has not unlocked the record. The customer wants the X to be placed in the field without his manually placing it in the field.
View 1 Replies
View Related
Nov 7, 2014
I have a POS system, packaged with Access Runtime, running on a PC and have developed a database system to provide additional function. I have no documentation to the names of the Forms or Controls in POS. My ADDON system does link to the POS Tables and has some Tables of its own.
At the time in the POS system where the cashier checks out the customer, they need to AltTab to my ADDON system to enter some information for the customer. They remember to CustomerKey from the screen on the POS system and key it into a Form Control in my ADDON system.I want to, from my ADDON system, read the value of the CustomerKey in POS and fill it in so the cashier does not need to remember/type it.
Is it possible to get the data from another already running Access database?I don't know the name of the control. Is it possible to run through a list of Forms and Controls in the POS system from my ADDON system?
I do know the name of the field in the Table and expect it to be current and might have to get that?Failing all that, is there a Collection of running Access databases? I could go through its Forms and Controls one time looking for what i want.
View 1 Replies
View Related
Nov 8, 2013
Is there any way to modify the progress bar so instead of saying "running query" it states the name of the query?
Like: Running Query [qryFRED] <progress bar>
View 1 Replies
View Related
Dec 10, 2014
I have a situation where I am using a maketable query to create a table and then I need to use append queries to then add additional records to the created table - some of these are just run once and some multiple times.
if possible, I do not want to hard code the query multiple times i.e.
Code:
DoCmd.OpenQuery "qryCreate_1"
DoCmd.OpenQuery "qryAppend_1"
DoCmd.OpenQuery "qryAppend_1"
DoCmd.OpenQuery "qryAppend_1"
etc
So is there a way I can run the make table query and then get some sort of loop to run the append query a number of times ?
View 4 Replies
View Related
Apr 9, 2015
I posted this within the Reports as well, but since this has a little bit of VBA decided to ask this here as well.
I have a report that is created from the following query (qryTotalProjectHours). What I am trying to do is get the total hours spent on Tasks within a given time period. A given Task can we worked on by multiple individuals and hence I need to find a way to aggregate the hours spent.
Code:
SELECT TasksEntries.Project, TasksEntries.Task, Sum(TimeTracker.WorkHours) AS TotalHours
FROM TasksEntries INNER JOIN TimeTracker
ON (TasksEntries.EmployeeId = TimeTracker.EmployeeId) AND (TasksEntries.TaskID = TimeTracker.TaskId)
GROUP BY TasksEntries.Project, TasksEntries.Task
I accept the start and end dates in a form and pass it like shown below. WorkDate is a column in the TimeTracker table and is not present in any other table.
Code:
strWhere = "WorkDate BETWEEN #" & txtMgrRptStartDate & "# AND #" & txtMgrRptEndDate & "#"
DoCmd.OpenReport "rptTotalProjectHours", acViewPreview, "qryTotalProjectHours", strWhere, acWindowNormal
When the report is invoked, I get a box where it says
"Enter parameter value" for Workdate..
Is there anyway I can get rid of the prompt? I never thought you needed the column name in the SELECT statement to be able to run this.
I should add the I tried the query with the WorkDate hardcoded in there and it worked fine and returned the correct results
I have attached the cut down version of the database that I am working on.Open up the frmManagerReport Form
Leave the Employee drop down empty
Enter the start and end dates ( I have used 4/1/2015 and 4/30/2015)
Select the 3rd option "Generate Tasks by Total Hours"
click on Run
When you do that you will see the prompt come up. Enter any date and you will see the report. The report generated uses the results from the query and does not filter on the date selected in the form. This is what I have been struggling to fix since yesterday but have reached nowhere..
View 11 Replies
View Related
May 19, 2014
I found code at this website that is supposed to determine if a specific program is running on your computer. I have a couple questions about the code here. One, when I run it just the way it is and call it in the immediate window with the ?fIsAppRunning("word") command, it tells me "True" whether I have Microsoft Word open or not.
My other question is this: After the code is working properly, how can I add new programs to it? There are two programs the end user might need open to complete a process. One is called Extra and one is called tn3270 (this is how they show up in the Processes tab of the Task Manager). I think in order to add them to this code, I need to know a "class" to associate with them.
View 1 Replies
View Related
Oct 30, 2014
I am pretty new to VBA coding and need running queries on specific tables. This is part of a multistep process, of importing data that needs to be transposed before appending to the "cleaned" database. First, users will save auto generated, Excel workbooks from a machine into a designated folder. I have code that will import these workbooks (an unknown number at a time) into Access in separate tables by workbook.
Each table will have a similar name, but different extension (ie Sheet101, Sheet102, etc.). This is where the issue arises. The files are in long form, not wide. I have a series of queries (unfortunately, they're not SQL queries, but I can convert them to be) that transform the data from long to wide. However, I do not know how to go about writing code that will run the queries ONLY on the imported tables (again an unknown number of tables with similar names), not the rest of the tables in my database. I'm guessing it involves a do loop, but I am not positive.
View 8 Replies
View Related
Oct 30, 2013
I have a query I am trying to build currently which creates a running total based on set criteria. I essentially have three columns (All times are in minutes). The visit ID, the duration of a visit and the time difference between the current and previous visit. e.g.
ID Duration Difference
1 30 0
2 45 10
3 15 20
4 60 10
5 15 10
What I would like to achieve is the following:
ID Duration Difference running total
1 30 0 30
2 45 10 85
3 15 20 15
4 60 10 85
5 15 10 110
So a line will have the calculation of the current time + the difference between the current and previous visit if the difference is below 20. I have the following:
Code:
Public Function Cont20(MyVal As Long, MyDif As Long) As Long
Static OldValue As Long
Dim NewValue As Long
If MyDif >= 20 Then
NewValue = MyVal
OldValue = 0
[Code]....
Which I put as Cont20([Duration],[Difference])
The problem seems to be on the return aspect, its not calculating correctly. I had the formula in Excel which worked great, but this is proving troublesome. As a note the Excel formula was such that it would add the previous running total and then add the current duration and current diff. e.g. In cell A7 the formula would be A6+B7+C7 and so on.
View 6 Replies
View Related
Jul 13, 2014
I need to stop already ran procedure or function with vba code . So I use END command ans everything stops.. in some cases that is useful, but some times need I to do something else after I use END command, but after END everything stops...
LIKE THIS :
SUB ()
END
ME.CTL.SETFOCUS
'OR
CALL function
EXIT SUB
View 5 Replies
View Related
Aug 6, 2013
I wrote some code in Excel to open and run a module in Access. The code executes, but when I check the results I get no records, however if I just step back 1 line and rerun the query, I get records. Alternately, if I run the code twice it will get results the 2nd time.
The OpenCounter opens a Session in the terminal screen then performs a macro that writes to a temporary table.
Here is the code:
Dim db As ADODB.Connection, Rst As ADODB.Recordset
Dim Acc As Access.Application
Set db = New ADODB.Connection
db.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DBPath
Set Rst = New ADODB.Recordset
[Code] ....
One thing I tried with limited success was to tell the OpenCounter to open and close the table after it was done writing to it, but that seems like a lazy solution and it also doesn't always work.
View 1 Replies
View Related
Oct 9, 2013
I am using access 2010. I use basic error handling in my routines:
Code:
On Error GoTo errHandler ... exitHere: ... errHandler: MsgBox "Error " & Err.Number & ": " & Err.Description
The problem is lately; while testing I am running multiple queries in a routine. When it fails; its hard to identify which query has the problem. So I hit control break; debug and try to find it. After I fix it; I debug and reset; i get this continuing hourglass thing in the form of a spinning circle until I close and reopen the database. I think I need better error handling but not something really complicated because I need to put it in quite a few routines throughout the database.
View 2 Replies
View Related