Modules & VBA :: Passing TempVar To SELECT Query

Feb 25, 2014

Picture, if you will, a table with multiple fields, each of which contains the date of a certain action in the process tracked by each record. I have a standard report format that will be used to view the progress of the actions. I want to be able to sort the report - on demand by non-technical users - by whichever date field they choose.

I've created a form with a combo box that is linked to a table with the name of each field in the source table. A Macro has been configured to open the form when the report is opened, which will prompt for the selection of the sort field. That value is then captured into a TempVar.

When the user clicks OK control passes to a procedure in a module that executes a SELECT statement (SQL) that configures the Query that is used for report generation. The "ORDER BY" portion of the statement needs to be modified with the name of the sort field desired. If the statement is hard coded as, for example:

...ORDER BY Main.[Initiated Date] DESC;

it works fine. I want to use the value of the TempVar to provide the name of the date field (ex.: [Initiated Date]), but I can't determine the correct syntax to get the statement to accept it. Concatenating doesn't seem to work, and I've searched high and low for hints on the web. Here's one version of what I've tried (and which fails):

"...ORDER BY Main." & [TempVars].[SortParm] & ";"

The error returned by the above version is: "Object doesn't support this property or method"

(SortParm is the name of the TempVar, and it is correctly populating, and keeping, the value I need from the form.)

View Replies


ADVERTISEMENT

Modules & VBA :: Passing TempVar Value Into A Table

Dec 13, 2013

I have a form in which the user selects a combobox and this value becomes a tempvar called "un" on clicking a command button I need the value of "un" to be passed into a table."un" is a number.Here is what I have so far.....

Code:

CurrentDb.Execute "INSERT INTO timedata(startedby) " & _
" VALUES(" & TempVars!un & ")"

but seem to get syntax errors all the time.

View 6 Replies View Related

Passing A Field Name Into A SELECT Query?

Aug 8, 2006

I currently have a table showing activity for multiple staff and their availability throughout the day in 30 minutes segments.

I am currently trying to pull the information on who is working by 30 minute timeslice, but as the information is held in a different field for ech period, it is proving difficult.

My thought was to make a query rounding the current time to the nearest hour/half hour and use this to choose the field, but I don't know how to make a query which will allow me to pass a variable (Field name) into the Select query?

can anyone help on this, or have any other ideas?

Thanks
Andrew:

View 4 Replies View Related

Queries :: Passing Parameter To Select Query?

Jun 5, 2013

I have form with a button on it that launches a parameter-based Select query (which served as the source for a report). I didn't have any validation measure in place, so if the User supplied a bogus value, a blank report was generated. While not technically an error, it would seem more polished to generate a warning message if the User supplies a bad query value and prompt them to re-enter.

Having read other posts along these lines, I've added an unbound text box to the form which the User fills in first before clicking the button. When the button is clicked, it executes code that uses the DCount function to make sure the text box value is in the source table, and if it is then it runs the parameter-based Select query. My question is how to pass the value in the text box to the query as a parameter. Below is a sanitized version of the code that I've generated so far.

Private Sub SingleItemRptB_Click()
If DCount("[FieldName]", "[Table]", "[FieldName]=[TextBoxValue]") = 0 Then
MsgBox "Item not in database. Please check value and re-enter."
Else
DoCmd.OpenQuery "SingleItemQ", acViewNormal, acReadOnly
End If
End Sub

View 4 Replies View Related

Queries :: Assign Query Results To A Tempvar?

Nov 14, 2013

The Query

'SELECT Count(clubbox) AS MTSingles
FROM moves WHERE (((moves.cmrdate)>[Forms]![CPanel]![Text44] And (moves.cmrdate)<[Forms]![CPanel]![Text46]) AND ((moves.driverid)=[Forms]![CPanel]![Text38]) AND ((moves.move)=35) AND ((moves.clubbox)=32));'

returns about 60 records, how do i assign the results to a tempvars

View 9 Replies View Related

Queries :: Pass TempVar To Query That Is Selected From Previously Opened Form

May 23, 2013

I'm trying to create a query that supplies a form with data. I want to pass a TempVar to the query that is selected a from previously opened form.The TempVar is setting correctly and I can see if this if I place a textbox (NewCID) on the form showing the TempVar. The problem I have is displaying on the records according to that TempVar. If I set the query manually, i.e. "|Test|" then records are displayed but if I use the TempVar, which also displays |Test| then no records are brought back.

think it's something do with the vertical bar and that fact the field I'm searching on is a memo field, both of which I've no control over. I also have to use the Like statement because of this.Here's the query that works...

SELECT *
FROM dbo_ASSETS
WHERE ASSET_CID Like "|Test|"

and the one that I want to use, that doesn't...

SELECT *
FROM dbo_ASSETS
WHERE ASSET_CID Like [TempVars]![tmpvarCID]

I've even tried referring to the textbox instead of the TempVar, i.e.

SELECT *
FROM dbo_ASSETS
WHERE ASSET_CID Like [Forms]![AssetsCID]![NewCID]

but that doesn't work either.

View 2 Replies View Related

Modules & VBA :: Passing Parameter And Date To Query

Nov 10, 2014

I have the following Visual Basic code which I am using to dynamically pass the parameters "SAFP" and date 10/31/2014 to the query:

Option Compare Database

'------------------------------------------------------------
' Run_Risk_Assessment_Report
'
'------------------------------------------------------------
'Original macro code
Function Run_Risk_Assessment_Report()
On Error GoTo Run_Risk_Assessment_Report_Err
Dim dbs As DAO.Database
Dim test1 As DAO.QueryDef

[Code] ....

When I run the query, i get the error "Item not Found in this collection"

View 14 Replies View Related

Modules & VBA :: Passing Variables To More Than One Field As Query Criteria?

Feb 25, 2014

My problem is as follows, i have created a report that calculates the total volume of FSC Materials. The user picks two dates from Calender controls that the report will range from. However the needs have now changed and i am required to make the report filter further based on user input, the problem i'm facing is that i cannot figure out a way to pass values from different variables to the report separate from another here is the code i would usually use to pass data to a query/report:

Code:
Private Sub MonthlyFSC_Click()
Msg = MsgBox("Select the Start and Finish Dates you wish to Query.", , "Start / Finish")
Start = adhDoCalendar()
Finish = adhDoCalendar()

[Code] ....

However i am now trying to do this, but it gives me an error as it is trying to pass the values to one field:

Code:
Msg = MsgBox("Select the Start and Finish Dates you wish to Query.", , "Start / Finish")
Start = adhDoCalendar()
Finish = adhDoCalendar()
sql1 = "[ORDER DATE]<#" & Format(Finish, "MM/DD/YY") & "#"
sql2 = "[ORDER DATE]>#" & Format(Start, "MM/DD/YY") & "#"

[code]....

It is performing incorrectly within the case select and passing the wrong criteria, as it will only display results that meet the default values' criteria. However the date criteria is not be passed either.

View 4 Replies View Related

Modules & VBA :: Passing Parameter To A Query - Data Sent To A Table

Jun 5, 2013

I have a function that when called transfers a query recordset to an excel spreadsheet then emails it. At the end of the function I use code to write the date sent to a table. Each time the function is called I only need records in the query that have been modified since the last time the function was called. I have a field in the query 'LastModified' with a criteria '>[Enter Date]'. I then look up the date in the table and enter it manually. I know how to look up the last date sent in table using code but getting the >#SomeDate# in the query with VBA.

Code:
DoCmd.TransferSpreadsheet acExport, , "qryUpdateWebmaster", _
"C:SubmarinersUpdates_Sent" & fname & ".xlsx", True, "Webmaster_Update"

View 1 Replies View Related

Modules & VBA :: Passing Variables To Make Table Query

Sep 29, 2014

Access 2010 vba - I'm trying to pass a start date and end date to a date field in a make table query, and use the 'between' operator on that date field.

So I have a criteria on the date field like this "Between [dtStart] and [dtEnd]" and if I run the query manually it asks for 2 values and then works fine.

Here's the code I'm trying to run:-

Set qdef = db.QueryDefs("qryTest")
qdef.Parameters("dtStart") = StartDate1
qdef.Parameters("dtEnd") = EndDate1
Set rs1 = qdef.OpenRecordset(dbOpenDynaset, dbSeeChanges)

and I get the error "3219 Invalid Operation" on the last line.

View 2 Replies View Related

Modules & VBA :: Passing Data From Query To Textbox On A Form

Jan 7, 2014

I have a form with a date field, when the user creates a new record, I would like the date field to automatically fill with the most up-to-date date from the Orderdate table.

Basically I need the code to do the following when a new record is created;

Search the Orderdate table for the most recent date and then auto fill the date field on the form with that date!!!!

My thinking so far...

Private Sub Command34 - where would you set this event on the properties i.e. Before update or On Got Focus ?

Docmd.OpenQuery "QryFindMaxDate"

I'm not really sure how to pass the date to the text box on the form,

End Sub

View 7 Replies View Related

Modules & VBA :: Passing Excel Cell Date To Access Query

May 1, 2014

I'm having a rough time trying to figure out how to pass a date to an SQL statement that Excel VBA macro will run. The date is in a cell (A1) formatted as 'm/d/yyyy'. Let's say it's 2/1/2014. I want to run an SQL statement that retrieves data from a table where a field is greater than 'A1'. The table field is a date/time field and has values formatted as 'mm/dd/yyyy'.

I've tried various syntax on the Where but cannot get it to work.
sd = Range("A1")
SELECT [tn].[Date Submitted]
FROM[tn]
WHERE tn.[Date Submitted] > """ & sd & """

This results in the following where clause that does not work.
WHERE tn.[Date Submitted] > "2/1/2014"

View 4 Replies View Related

Modules & VBA :: Passing Values (From Two Column Listbox) To Saved Query

Oct 3, 2013

How can I pass two (2) values to a saved query ? These values are in a form that has a listbox with two (2) columns. The name of the form is 'Previous Evaluation Form'. I'm able to retrieve the values from both columns of the listbox in the form and I've already created the query. Both are working fine, but can figure out how to pass the query's criteria to select records for 'Name' and 'Date' columns of the query. Below is what I had in the 'Criteria:' of the query. What wrong with the code that is placed in the query's 'Criteria:' ?

Forms![Previous Evaluation Form]![Individuals].Column(0)
Forms![Previous Evaluation Form]![Individuals].Column(1)

View 3 Replies View Related

Modules & VBA :: Passing Variable From Excel To Fire Access Query

Dec 17, 2014

I'm running a VBA routine in Excel that loops through a lot of data. As part of the process, I'd like to pass a variable from Excel to an Access database that is open and have it run a query based on that value.

View 4 Replies View Related

Modules & VBA :: Query To Search For Records - Passing Parameters In A QueryDef

Aug 27, 2013

I have a query that searches for records that are between two dates using the WHERE clause. The two dates are referenced to two respective text boxes on a form. On the same form I have a button that will launch the query in VBA using querydefs. I get the error 3061 saying I need to input the parameters. Therefore I am a bit unsure how to set the parameters in VBA. So far I have done this:

Code:

Dim Db As DAO.Database
Set Db = CurrentDb
Dim QDef As DAO.QueryDef
Dim rst As DAO.Recordset
Set QDef = Db.QueryDefs("Rqt_F_BrokerageMandate_MF3_TEST")

[Code] ....

Where Date_VL is the field to be filtered. I know this is wrong but all examples I have seen have equated the parameter to a fixed value i.e 30/12/2012 for example, but I want this to be at the users discression. The only way I know of to get around this at the moment would be to write a temp query in VBA with PARAMETERS in the SQL code instead using the method above/

After this I'm going to assign the recordset to a matrix but that's a different story!

View 10 Replies View Related

Modules & VBA :: Getting Max From SELECT Query

May 13, 2015

I currently have 2 queries..

Query 1 select statement getting count of field

Query 2 getting max of Query 1

Instead of the queries I want to do this in vba with a recordset

Code:
' Select from first query
sql = "SELECT tblOriginal.ROUTE, Count(tblOriginal.ROUTE) AS CountOfROUTE " & _
"FROM tblOriginal " & _
"GROUP BY tblOriginal.ROUTE " & _
"ORDER BY Count(tblOriginal.ROUTE) DESC"
' Select max from result of first query
sql2 = "SELECT Max(qryRouteCount.CountOfROUTE) AS MaxOfCountOfROUTE " & _
"FROM qryRouteCount;"

The slq works fine for the first Query, I could then do a iMax = rs("CountOfROUTE") to get the max value as they are ordered.

but how can I write sql 2 so that it selects the Max from the Query 1 select statement.

View 4 Replies View Related

Modules & VBA :: Select Query Returning String Instead Of Value

May 2, 2014

Why is strCreditCheck returning the actual query string and not the result? Of course, this is not working.

Code:
Private Sub b_PrintWorkOrder_Click()
Me.Requery
Dim strCreditCheck As String
Dim strCompany_id As Integer
Dim stlinkCriteria As String

[code]....

View 6 Replies View Related

Modules & VBA :: How To Create And See Results Of SELECT Query

Mar 22, 2015

I was beginning to think I had got the hang of creating queries on the fly in VBA. After several hours I have just learned that docmd.runSQL does not work for simple SELECT statements. I'm not going to worry about why that would be. I'm sure there's a jolly good reason.

So... I am able to dynamically create the SQL string for the SELECT statement that I need.

How do I run it? It just needs to return results as a datasheet so I can see them. I'm running Access 2013. I've been searching on this subject for quite a while and found many references to DAO, ADO, ADODAOD, YODELAEYYOUDELAYIO! and other things I don't yet understand ...

View 8 Replies View Related

Modules & VBA :: Programmatically Find And Select Item In Multi Select List Box

Apr 23, 2015

I have a multi slect list box (simple) and I need to find and select an item using vba - e.g., the bound column is the ID field and I need to select a specific ID (which will be different each time) as opposed to selecting the 100th record for example. How do I do this?

View 2 Replies View Related

Modules & VBA :: How To Process A Select Query Using Listbox Value As Where Variable

May 6, 2015

I am using Access 2013. I have the ability to pull a selection from a listbox. I can create a Select Sql string using that variable

sql As String, strCompany As String, strWhere As String
strCompany = strCompany & Me.lstResource.Column(0, varItem)
strWhere = "[Company name]=" & "'" & strCompany & "'"
sql = "select * FROM tblResources WHERE " & strWhere

From here I have trouble. I see lots of examples to run an active query but not much on a select query. I have tried a number of things with no success. How to use this select statement to actually run against an existing access table? I am not putting it into a form or report at this time, just running the query to check results.

View 1 Replies View Related

Modules & VBA :: Write Select Query That Will Search The Data From Bottom To Top Of Table

Dec 3, 2013

see below the code . The select statement searches the Printpoolno value from the top to bottom in table tblmaster. As in my table tblmaster there are thousands of records and it takes long to search for that Printpoolno from the table . Is there anyway we can write a query that will search the table from bottom to top as the Printpoolno will always be in the bottom records and not in the top records.

Code:

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Long

[Code].....

View 3 Replies View Related

Modules & VBA :: Criteria On MS Access Query Not Working With Multi-Select Listbox

Aug 22, 2014

I am attempting to filter records using a multi-select listbox, but all records are being returned. Here is my code.

Private Sub btnKeyboxCount_Click()
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String

[Code] ....

View 1 Replies View Related

Modules & VBA :: Getting Error End Select Without Select Case?

Sep 5, 2014

When I run the below code I am getting the error "End Select without Select Case" I figured it might be because I have the "End Select" before the "End With" however when I move the "End Select" after the "End With" I get the error "Loop Without Do".

Code:
Private Sub cmd_Update_Conditional_Codes_Click()
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset

[Code].....

View 3 Replies View Related

Modules & VBA :: Passing Image To Another App?

Dec 27, 2013

I want to use an On Click event on an image field on a subform to fire up either Windows Photo Viewer or Corel PaintShop Pro with that image active - but don't really know where to start. DoCmd, Shell ?

View 5 Replies View Related

Modules & VBA :: Passing Information From One Form To Another

Sep 25, 2014

I have created Form1 with a button and after I click the button Form2 appears (frm_Rollover_Progress). Form2 is a (poor mans) progress indicator that makes some labels visible after a section of a query has run. I have set the first label on the form to Me.lblProgress1.Visible = True but I keep coming up with Compile Error - Method or data member not found. However, when I put a button on the second form and copy in the exact same code then Me.Label1.Visible = True works. I have tried to SetFocus to an item on Form2 but still does not work.

'Open progress form to show progress indicator
DoCmd.OpenForm "frm_Rollover_Progress", acNormal, , , acFormReadOnly

'Add current changes to Total Changes table

Me.lblProgress1.Visible = True
Me.Label1.Caption = "10%"
DoCmd.OpenQuery "qry_Change_AddedQX2", acViewNormal, acAdd
Me.lblProgress2.Visible = True
Me.lblProgress3.Visible = True
Me.Label1.Caption = "30%"

View 2 Replies View Related

Modules & VBA :: Passing Variables To A Sub Routine

Jan 13, 2014

I have a public sub routine which requires parameters to be passed to it when I call it from an access form. When I try to enter the code to call the sub I get a compile error. I've also tried calling it from another sub in the same module but get the same compile error - see below.

Code:
Sub EmailData(Datafile As String, To_mail As String, CC_mail As String, Subject_mail As String)
'code to use variables passed in
End Sub

[Code]....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved