Can someone please tell me if it is possible to pass in a parameter for the sorting field to a stored procedure in MS Access.
When I tried to execute a query similar to below, neither did the query give me an error nor did it execute correctly.
PARAMETERS ORDERBY_FIELD as Text;
Select * from Employees Order By ORDERBY_FIELD;
It will be great if someone could help me with this.
Hello! First time post, and I'm desperate for some help.
I am trying to use a loop through a recordset, pass the value of the current record into a WHERE clause, run an append query based on the value of that record THEN loop through the recordset, pick the next value, pass it to the WHERE clause, run the append, etc. I finally figured out how to set a variable as a parameter for my WHERE clause and how to loop through a recordset.
My problem is this, I cannot get the variable (myvar) to update with the next value from the next record in the recordset. My code loops through all records just fine, but it only appends the query result based on the value of the first record. In short, I get 134 appended records all with the same value because myvar never changes.
My code looks like this:
Public Sub OpeningARecordset() Dim db As Database Dim rec As Recordset Dim myvar As Double Set db = CurrentDb() Set rec = db.OpenRecordset("Select SRS_SKU FROM tblUniqueSKUListing") myvar = rec("SRS_SKU") rec.OpenRecordset Do Until rec.EOF rec.MoveFirst DoCmd.RunSQL ("INSERT INTO [Loc Group Names] ( SRS_LOCGROUP, [Loc Group] )" _ & " SELECT tblUniqueSKUListing.SRS_SKU, tblUniqueSKUListing.SM_DESC" _ & " FROM tblUniqueSKUListing WHERE (((SRS_SKU)=" & myvar & "));") rec.MoveNext Loop rec.Close End Sub
Can anyone shed some light on how I get myvar to update with the value of the next record once the append is done?
Basically, my database holds records of sites in the UK, and I have a select query (qry_SumGIS3) that opens up a summary report (rptSumGIS3) when a button is clicked on the menu page. The report opens perfectly, showing me all the information I need to know about all the sites in my database. However, it is ignoring the Order By Clause I have specifically told it to do. I want to order the records that appear in the report by a calculated field (OBJ_WS_OVERALL_CALC) in descending order (highest to lowest percentage). Instead, it is ordering it by the site id (RTP_ID). How can I stop it doing this?
This is my code (that was created in the SQL view of the query design): "SELECT MEASURE1.OBJ_WS_OVERALL_CALC, [Tab 1: Factual].RTP_ID, OBJECTIVES.OBJ_ID, OBJECTIVES.OBJ_NAME, MEASURE1.MEASURE_ID, MEASURE.MEASURE_NAME, MEASURE1.MEASURE_SCORE, MEASURE1.MEASURE_WEIGHT FROM [Tab 1: Factual] INNER JOIN (OBJECTIVES INNER JOIN (MEASURE1 INNER JOIN MEASURE ON MEASURE1.MEASURE_ID = MEASURE.MEASURE_ID) ON OBJECTIVES.OBJ_ID = MEASURE.OBJ_ID) ON [Tab 1: Factual].RTP_ID = MEASURE1.RTP_ID ORDER BY MEASURE1.OBJ_WS_OVERALL_CALC;"
The red line is the part of the code that I think is being ignored.
I am working on a commercial website that is using ASP and an access database.
I have a pretty elaborate select statement that works, except for part of the ORDER clause.
Here is the scenario.... my client sells automotive parts...
Table 1: (itemsku) holds part numbers Table 2: (itemveh) holds vehicles that work with those parts along with some descriptive clarification (cab size, bed size, years, ...) Table 3: (make) holds the vehicles make name (ford, chevy, ...) Table 4: (model) holds the vehicles model name (F150, Ram, Silverado...)
I need to get a list of parts and their approriate descriptions and sort it by Make, Model, Specific Description, and year.
((itemsku left join itemveh on itemsku.id=itemveh.itemsku_id)
left join model on itemveh.model_id = model.id)
left join make on model.make_id=make.id
where itemsku.item_id=4
order by
make.name,model.name,itemsku.desc_sku
If I put it as listed, all sorts properly, except for the years. As soon as I add to the end of the order by....
, itemsku.yr_beg desc
Then, the desc_sku portion does NOT sort properly, but the years do. I have tried dropping the desc as well to see if that would help, but the desc_sku does not play into the sort factor if the yr_beg is added.
Am I missing something or is their a limit as to the number of fields in an ORDER?
From a performance perspective, does it matter in what order a number of clauses are specified ? For example if many records satisfy ConditionA but few records satisfy ConditionB, is it better to put ConditionB first ?
SELECT Fields FROM Table WHERE ConditionA and ConditionB or SELECT Fields FROM Table WHERE ConditionB and ConditionA
I have a Report that uses a query as it's record source. I have the query ordered by a field, which works as expected in the table view of the query. In the report, however, the ORDER BY clause does not seem to carry through. The field is not sorted Ascending. What's going on?
SELECT Field1, Field2 from table1 where table1.Field2 in (1,2,3)
and now i need to parameterize this query.... I tried with
SELECT Field1, Field2 from table1 where table1.Field2 in ([Parameter])
Now the problem is... it is working fine with only one value For example if I input 1, it provide the required result. however, if I input 1,2 it doesnt provide a single recordset
I changed the datatype of parameter from number to text and also tried different way of inputting number like "1,2" , 1,2, but still problem is the same...
Can someone please guide me where I am going wrong
i set run query A with parameter as value of combo box 1 of form 1...i want to run same query (Query A) with parameter as value of combo box 21 on form 2 or combo box 1 on form 1.
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.
After some research I thought I had found a neat way to SELECT records from a table based on an 'IN' clause and sort them in the same order as the values for the 'IN' clause... i.e.
Code: SELECT Unique_No, Table_Name, List_Order FROM My_Table WHERE Table_Name = 'Titles' AND List_Order IN (3,1,15,4,5,12,7,2) ORDER BY INSTR('3,1,15,4,5,12,7,2', List_Order)
Unfortunately, this returns list_order 5 just after 15 and list_order 2 just after 12, thus
Using Access 2003. Really need some help. Have the below code which executes a SELECT query and passes the results as an excel spreadsheet attached to an email. Problem is that the query store_report has some parameters that need to be passed to it. Is there a way that with my current code I can pass those parameters. If not is there some other commands or code I can use to accomplish this?
DoCmd.SendObject acSendQuery, "store_report", acFormatXLS, _ "john@john.com", "c.w.k@gmail.com", , _ "Store Reports", "Here are your reports.", True
I currently have a student membership database with a main Members form. When it opens it prompts me for a parameter which determines if only active, inactive or all members will be displayed. Once the form opens I use a combo box to search through all of the records. Currently this combo box lists all of the members names regardless of the parameter. To address this I set the same parameter query for the combo box. This works fine but it means that I have to enter the same parameter twice. What I would like to do is to have the 1st parameter, when the form opens, pass to the combo box. Any pointers would be greatly appreciated.
Also, if anyone knows of a more elegant way to accomplish this other than using a parameter query please feel free to pass this along.
I have a form with a combo box that when I select a value I want the hidden value (UserID) passed to a query that would open up a form that is set up like a data sheet. When I try to set up a form that would display the records related to the UserID I end up getting all records and the UserID column replaced with the passed value when I set the control source to = Forms!frmEmployeeInstances!cboShiftEmployees.Colum n(0) I don’t know if I can pass the value to a query (if the query can even acknowledge the passed value), so any help would be greatly appreciated. I have the OnClick set to open a form called frmShowInstances via a Macro but I could never get the Where Condition to work either.
I have list (server names) in excel file (200 rows), I would need to query the Model of these from in MS access, How do I pass these list in excel to the query.. I can't be running the query 200 times nor I could type them one by one.
I know this is probably a basic question- but Im not finding a clear answer here.
Basically- I have a value that I want to select from a drop down box on a form (not created yet). That value will get inserted into my query for a calculation I am doing. The form will pop up the results of the query in a table/dataset.
How do I designate the variable in the query that is being inserted from the form? I am using Access 2002- is there a way to visually perform this task (ie- drag/drop type thing)? Thanks guys!
I'm trying to the following sub to automate the creation of RecordSets but I'm confuse how to get it done properly.
Public Sub OpenRecordSet(SQLString As String, NameRecordset As Object) Set NameRecordset = New ADODB.Recordset NameRecordset.Open SQLString, adOpenStatic, adLockOptimistic
I want to pass the name of the recordset as a parameter but I don't know how to set it.
trying to pass a textbox value as parameter in a sql query.I have a multiline textbox and I use it to find several values in the database, so in this textbox all the values are pasted each per line and I have a small code to convert it to single line comma separated values.This is an example:The user enter the data:
[Text0] A1C556CC3C-TNNN C010070H13
The code convert this data to a single comma separated string and runs the query: ex: "A1C556CC3C-TNNN","C010070H13"
Code: test = """" & Replace([Forms]![Search]![Text0], Chr(13) & Chr(10), """,""") & """" [Forms]![Search]![Text0].Value = test DoCmd.OpenQuery "FindPartNo", acViewNormal, acReadOnly
In the SQL code I use the IN operator to find the exact value for each record:
[code]...
I'm passing the value incorrect into the sql code?
Hi - I am looking for some help understanding the instructions in the msdn article on how to pass a parameter from a DAP. Please refer to the article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k2/html/odc_PassParam.asp
I was able to follow the instructions until Page 2 of this article...where it says: "Add the functions to write, read and delete cookies in a separate global script block."
I do not understand how to create a global Script block. Do I just copy and paste this code right below the 1st code on Page 2? Or, is there a way to create a global script block separately and add this code there?
I am unable to find that much Online resources on DAP as other Access topics. I thought posting my question here would be the last resort for assistance! :confused:
I have an append query that contains a parameter [PTIdent] under the field named PTID. I would like to be able to set the parameter through VBA from a control on a form eg Form!PTID
I use the following code as normal Private Sub Command19_Click() On Error GoTo Err_Command19_Click
Is there a way within this code to do this? I realise I could set the form criteria within the query itself. However I wanted to be able to use this query from multiple forms.
I have a query set up which needs to have different criteria at run time depending on values selected by the user. If no option is specified, I need to pick up all records with 'Nulls' in them else, if date is specified by user, I need to pick up all records with date > than specified date. The query is able to pick up the date value from an unbound text box in the form. I used the same field in the form and populated "Is Null" in the field and it does not work. How do I pass this as a paramater to the query from the form? Is there a way around without setting up 2 sets of queries and reports?
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
I have a form which users can toggle whether they want to only see entries that has data in a certain field. Previously I have set up a separate query with a hardcoded 'Is Not Null' in the criteria, and set the form to call the different queries based on the status of a toggle button. This time there is 22 queries that need to be modified so I'm hoping there's a better way.
I have a hidden textbox on my form that has value "Is Not Null" or Null based on the position of the toggle button.
In my query for the field criteria I have [Forms]![MainForm].[txtCriteria] where txtCriteria is the textbox previously mentioned.
I'm having a very simple issue (I think) trying to pass a textbox value as parameter in a sql query.I have a multiline textbox and I use it to find several values in the database, so in this textbox all the values are pasted each per line and I have a small code to convert it to single line comma separated values.This is an example:The user enter the data:
[Text0] A1C556CC3C-TNNN C010070H13
The code convert this data to a single comma separated string and runs the query: ex: "A1C556CC3C-TNNN","C010070H13"
Code: test = """" & Replace([Forms]![Search]![Text0], Chr(13) & Chr(10), """,""") & """" [Forms]![Search]![Text0].Value = test DoCmd.OpenQuery "FindPartNo", acViewNormal, acReadOnly
In the SQL code I use the IN operator to find the exact value for each record:
FindPartNo sql query:
Code: SELECT Classifications.BU, Classifications.WisperPlantID, Classifications.PartNumber, Classifications.PartDesc, Classifications.US_CL_Code, Classifications.MX_CL_Code, Classifications.TARIC_CL_Code, Classifications.COEProject, Classifications.Supplier, Classifications.BrokerRequest, Classifications.CreatedBy FROM Classifications WHERE Classifications.PartNumber In ([Forms]![Search]![Text0]);
The problem here is, the query doesn't return results but if I modifiy the query and I put:
Code: WHERE Classifications.PartNumber In ("A1C556CC3C-TNNN","C010070H13");
... the query returns the correct results.I'm passing the value incorrect into the sql code?
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"
SUMMARY: In Access 2007, can I pass a Column Name as a parameter from a Combo Box in a form?
DETAILS: I would like to use a String value from a Combo Box as a parameter in a Inner Join query: ... WHERE (((AAA.HSC) Like Forms!My_Form!My_TextBox) AND((CCC.Forms!My_Form!My_ComboBox)="X"))
Where "CCC is a Table from my Join Query
I'm able to run the code above without generating any errors. However, instead of the query accepting the value from the Combo Box, it opens a pop up asking for the value of "CCC.Forms!My_Form!My_ComboBox", not once, but twice! After it finally runs, the result set is empty when it should not be. I also find it strange that it is asking for the combo box value with the Table name appended to the front.