Modules & VBA :: Manage IN Clause Using Parameters
Dec 10, 2014
I am trying to dynamically change the IN sql from within VBA using parameters. for some reason i have no luck, no errors shows up, but it's actually not picking up the criteria.
Code:
THE SQL IN STATEMENT
In (select RemID from [ReminderAssignees] Where RemDate between [Date1] and [Date2] And [sDismiss] )));
Code:
THE VBA CODE
qdf.Parameters("date1") = Date1
qdf.Parameters("date2") = Date2
Select Case iDismissed
Case 0, 1
qdf.Parameters("sDismiss") = "1=1"
Case 2
qdf.Parameters("sDismiss") = "(not isdate(Dismiss) or Dismiss > #" & Now & "#)"
Case 3
qdf.Parameters("sDismiss") = " isdate(Dismiss) and Dismiss < #" & Now & "#"
End Select
I have this code below which pulls a report based on the current date, I wanted to be able to pull the same report by entering between 2 dates as is done in a query using parameters.
Hi all: I am trying to filter a query based on user input from a ListBox. I loop thru the ListBox and build a comma-delimited list of IDs. It takes one parameter, but if there are 2 or more items in the list, it returns nothing. It's not the query, because if I hard code the same comma-delimited list into the SQL query ("...WHERE CategoryID IN (1,2,3)") it works fine.
This is the query:
SELECT tbl_Subsidiary.SubsidiaryName AS Brand, Sum(tbl_Placeview.Duration) AS SumOfDuration FROM tbl_Subsidiary INNER JOIN tbl_Placeview ON tbl_Subsidiary.SubsidiaryID = tbl_Placeview.SubsidiaryID WHERE (((tbl_Placeview.AirTime) Between [Forms]![frmTopBrandsByCategory]![txt_DateFrom] And [Forms]![frmTopBrandsByCategory]![txt_DateTo]) AND ((tbl_Placeview.CategoryID) In ([Forms]![frmTopBrandsByCategory]![txt_CategoryList]))) GROUP BY tbl_Subsidiary.SubsidiaryName ORDER BY Sum(tbl_Placeview.Duration) DESC;
You can see I'm getting the list of "CategoryID" from a text field; after getting my comma-delimited list from the list box, I assign it to a hidden text field. In debug I can see that the list of IDs is built correctly.
I found the below link that looks great and works.
[URL] ....
Te only thing is that I don't have much control over it and would like to build something similar as we also need to work with access 2003 (still )Any way to find how the code works (if there is some of it hidden in access)?
Code: TRANSFORM nz(count(T_qa.qaQAPK),0) AS SumOfQAs SELECT month(qaDate) AS QAmonth, Count(T_qa.qaQAPK) AS QAs FROM Q_ALL_qa GROUP BY Month(qaDate) PIVOT month([qaDate]) IN (1,2,3,4,5,6,7,8,9,10,11,12);
This query is record source for a report, then this report show all calculations in a form.
I have 7 of each (query + report) all showing on the same form.
All those queries calculate data for all departments.
In the form, I have placed a combobox.
What I want is to create a vba code which will add clause WHERE to all queries at the same time and then run it.
Code: WHERE qaDeptFK=Forms!F_CompLvl.cboDeptStats
However, if nothing has been selected in the combo, I want the queries to calculate data as normal, for all departments.
Where do I place the vba statement? Is it under combobox AfterUpdate event?
I am planning to use this: (As I never done it before) [URL] .... Modifying SQL On-The-Fly section
I'm trying to get an SQL statement to take a value from a combo box in a WHERE LIKE clause.
For example:
INSERT INTO tblInspectionTempp (BuildingID, DoorNumber) SELECT tblDoorData.BuildingID, tblDoorData.DoorNumber FROM tblDoorData WHERE tblDoorData.BuildingID LIKE = '[Forms]![fmInspectionColumns]![cmboBuildingID].Value'"
The errors I'm receiving are either Missing Match or incorrect Syntax, depending on my trial and errors methods regarding the WHERE clause.
I have an update sql statement that isn't quite working properly.
My where clause has 3 criteria. *print = -1 *stDocCriteria (project_num and client_id)
Below is what the code looks like.
Code: updateSQL = "update tblTimedTasks set printed =-1, invoice_date = Now() where print = -1 and " & stDocCriteria
Add watch: so you guys can see "stDocCriteria"
Code: updateSQL = "update tblTimedTasks set printed =-1, invoice_date = Now() where print =-1 and ([project_num]= '140012' And [client_id] = 87)"
I want to only updates records that meet all three criteria. The above sql not only updates all records that satisfy stDocCriteria regardless if print is -1(true) or 0(false).
I am having trouble opening Form 2 to the same record as the record in Form 1. Form 1 is a continuous form of questions. When certain response is given, I want to be able to add more information to the "additionalcomments" column for that record. I want to have the additional comments pop up in a new form.
Form 1 is based off of a query with no unique ID. I need the second form to open on Eval_Number and Question_Number. I have tried...
Code: If Me.Response = 0 Then DoCmd.OpenForm "frmadditionalcomments", acNormal, , "[Eval_Number] =" & Forms!ESVWL1Trainee!subfrmreponses.Eval_Number And [Question_Number] = " & Forms!ESVWL1Trainee!subfrmreponses.Question_Number " End If
and this tells me the object doesn't support the method. Is the SQL incorrect? Is it the way its setup?
I want to that the WHERE clause for a SQL statement that I am using options on a form to build. I intend to use the clause in opening a datasheet form.
This is the code I have for getting the substring
Code:
Dim intPos As Integer Dim tempString As String Dim BaseQueryFormStr As String 'BaseQueryFormStr is used to reopen the BaseMasterQueryFrm with the specified parameters tempString = "WHERE"
I am trying to calculate annual percentiles of a large set of data and I have only been successful at retrieving the percentile of the entire data set (and not by the grouping). See provided example database for code/query. Query1 is what I want to happen to make the Percentiles table.
Connecting Access FE to SQL SERVER BE Connection is fine. I can open and close it and other queries work fine. I have only one problem with the SQL in one query
Code: With rstRPT If FirstRecord = True Then .Open "SELECT Min([" & SourceTbl & "].[3Order ID]) AS MinOf3OrderID " & _
[Code].....
why it wants to see the variable as a column name?
I've been trying to work up a where clause that is generated by a button click event on a report. The workflow that i'm trying to obtain is as follows:
1) A report is run to determine the remaining work orders that need to be processed. 2) A button that is placed on that report is to be clicked, taking the user to the form associated with that work order, so it can be processed.
What i've been able to do so far is capture the unique ID for the work order and then print that in a message box. I can then open the form.
What i haven't been able to accomplish thus far is to open the form to the correct work order.
Things I've tried : I started trying to use the macro with the search for record option and using the where clause. Not successful. I am a little more comfortable in using vba so i switched to that pretty quickly.
Code: Private Sub btnJobEntry_Click() 'GOAL: open the work order form to the correct entry 'METHOD: store the uniqueID to a variable, then use that in the open command's where clause Dim strJobID As String 'store the unique ID in the variable
[Code] ....
I've put the strJobID variable in both the filter and where clause sections of the DoCmd but it just opens the form to the first entry. I'm fairly confident i'm not applying the filter/where clause correctly by using the incorrect syntax.
This is my first time writing a pass through query pinging sql tables using an input parameter from a form. I have gotten as far as executing the query but I can't seem to display the result to ensure it's pulling the right records. I also want to be able to append the records to a table. Below is the code I have written so far:
Sub GETRT()
Code: Dim db As DAO.Database Dim QDF As QueryDef Dim STRSQL As String Dim RS As Recordset STRSQL = "SELECT * FROM LAB_MESR.ODM_RT_DAYS" & _ "WHERE LOCATION_ID=" & [Forms]![PARMS]![STR_NBR] Set db = CurrentDb Set QDF = db.QueryDefs("001:GET_LT") QDF.SQL = STRSQL End Sub
I have a sample database (attached) where I have a form called frmVoteHeadsOne. The voteheads that I have are swimming (Swim) and transport (Trans), which both appear for data in a table. On the form, from the combo list, I would wish that if I select swimming, for example, only Mark Tyler's name is returned since he has paid 2000; if I select Transport from the same list, only John clement's name is returned.
My purpose for doing this is because in the actual database, I have 21 different voteheads which I would like to get different results from based on what the user selects from the combo list.
My manager wants to be able to implement a kind of punch card system for managing staff time. I'm thinking we could make a database that links to a folder in Outlook. Staff will be able to send an email to the inbox saying that they are, for example, going on a break at 10:50, and then another at 11:05 saying they have returned and are back to work.
This would probably add up to around 500 emails per day with the number of staff we have, so I don't want to have to keep all the emails to be able to add up break times etc.
I'll be extracting the timestamps, name, break description etc from the email and storing them in another table. What I would like to know is whether Access would then be able to delete the email from the inbox (or modify it in some way to reflect it has been accounted for), or whether this would have to be a manual task?
During the course of it's development I have created about twenty tables whose sole purpose is to house data for use in combo and list boxes. They have no other purpose.
I am now in the process of creating the maintenance side of this project and how to manage these lists. In the past I have created a form with a multitude of subforms to manage these lists.
I am working on a db for a restaurant expense account. I am trying to design a multi-user login form to allow administrator and other users to log in the data entry form. I am a newbie to MS Access.
I am trying to create a database to analyze expiration dates of multiple products.
Let me lay out what I am trying to accomplish.
I have 5 ambulances, each ambulance has the same quantity of medications on it. There are three separate locations medications are stored on each truck. Each month I need to be able to update expiration dates, query what medications will expire by a set date and where exactly they are located.
SO here is the structure as I see it.
Ambulance 1 contains, a drug drawer with approximately 30 different medications, a trauma bag with about 10 different medications, and a blood glucose kit with 2 different medications. Now some of medications are repeated in the different locations, but have different quantities. The medications will never all have the same expiration date, and medication 1 might have 8 vials, where medication 2 may have 4 vials. I would like my form to be dynamic based on the inventory level of the medications. That way if we decide to keep 10 vials instead of 8 the form will then require the 2 extra data points.
The tables I have created so far...
table 1 lists all the ambulances table 2 lists medications in the drug drawer and the inventory level table 3 lists medications in the trauma bag and the inventory level table 4 lists medications in the blood glucose kit and the inventory level
I need to create a table to store my expiration dates for each of the locations in each of the ambulances.
I need to create a form to simplify the entry of the data into those tables and I want the form and table to be dynamic to the inventory level.
Table: DailyExport Field: FailureGrouping (actually is offices)
I want to export all the fields from DailyExport each of our 9 offices to Excel, whetjer or not they have date in the DailyExport table. So if not, the exported workbook would only have columns headings.
I need to loop through the nine offices and export each office report to Excel.
Dim StrQry As String Dim strfullpath As String Dim SOffice as String strSQL = "SELECT * FROM DailyExport WHERE FailureGrouping = " & SOffice strfullpath = "Y:" & SOffice &" "& Format(Date,"mm-dd-yy") & "_Failures.xlsx" DoCmd.TransferSpreadsheet acExport, , FailureGrouping, strfullpath, False
I have code for calling stored procedure with parameters,which is as follows
Dim qdf As DAO.QueryDef, rst As DAO.Recordset Dim IdValueToProcess As Long
IdValueToProcess = 221177 ' test data Debug.Print (IdValueToProcess) Set qdf = CurrentDb.CreateQueryDef("")
[Code] ....
And my stored procedure is
Code: ALTER PROCEDURE [dbo].[spItemDesc] @ItemNo varchar(200) , AS BEGIN set nocount on ; select ProductDesc1,ProductDesc2 from ProductDatabase.dbo.tblProductInfo where ProductNumber = @ItemNo END
I have a list box on an unbound main form, which contains a rowsource consisting of files in a certain folder. The listbox is unbound
when I change an item in a subform, the listbox should update to show different items from the same folder.
Now it is updating correctly, so the rowsource appears to be correct, , but then the listbox behaves strangely - with the first item being sort of permanently selected - or at any rate - strange selection behaviour
out of interest, changed it to a combo box and it works correctly. so there must be some difference between the two?
After investigation, it might be this : [URL] ....
The appearance is similar to what is described in the thread.
although I have played with the strings to get them shorter without getting it work correctly. very strange
if I run the code to update the listbox from the subform, either directly, or by running as sub IN the main form, it produces this strange behaviour. If I run exactly the same code directly IN the main form, it seems to work properly.