SQL Server - Passing Parameters

Jun 15, 2005

Hi,

After years and years of working with Jet, I am now trying to use SQL Server backands and am having problems passing parameters to a stored procedure.

How can I build a query which where I can say "WHERE ([AField]=""" & Forms!BlarBlaretc.value & """)" as I can in access because as I understand it you can not look at front end information from the SQL backend.

Any help (and start at the beginning) would be much appreciated.

Cheers

Stu

View Replies


ADVERTISEMENT

Passing Parameters To A Query

Feb 1, 2006

Guys I need your help/Advice...

In my Access Database I have a query (lets say qry1) and in this query i have 2 fields for start and end date, which is provided by 2 Get functions.

also i have qry2 based on qry1
then qry3 based on qry2
and finally qry4(using sql in code) based on qry3, and non of these 3 queries have the start and end date fields.

now here is the problem: I am trying to set the criteria in qry4 and then open a record set on this query(qry4) to use the data that it pulls out...


strsql = ""
strsql = "SELECT Sum AS AREA_TOTAL " _
& "FROM qry3 " _
& "WHERE ENERGY_AREA like '" & Area & "';"

Set MyDB = CurrentDb

Set rst = MyDB.OpenRecordset(strsql)



but when the last line is executed I get this error message:

Runtime Error '3061':
Too few parameters, expected 2.

i also tried doing this:

strsql = ""
strsql = "SELECT Sum AS AREA_TOTAL " _
& "FROM qry3 " _
& "WHERE ENERGY_AREA like '" & Area & "';"

Set MyDB = CurrentDb


MyDB.QueryDefs("qry4").sql = strsql

Set rst = MyDB.OpenRecordset("qry4")


but when the last line is executed it gives me an error message saying that the query does not exist or the name is not spelled correctly. (Ps. I have created the query and the criteria does update once the Select statement is run in the code!)

again the reason for this is that the query has not been populated as the main query (qry1) needs 'strat date' and 'end date'!

Is there anyway I can pass these 2 parameters to qry4 directly using code? If there is a way then this will definitly work as i tried opening the query manually in the Query window and after I input the 2 dates in the input box the query ran successfully!

I would appreciate any help/suggestion guys, I need to sort this out quickly as i have a deadline... Cheers

View 1 Replies View Related

Passing Parameters To A Form

Dec 22, 2006

Hi all,

I have a continuous form that is bound to a SQL Server view.

For each record in my form I have a button, which when pressed opens up a second form. The second form is bound to a stored procedure that takes a parameter. The parameter value that I want to pass to this second form is the value of one of the fields in the first form.

I did the following in the click event of the button on my first form:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "SecondForm"

stLinkCriteria = "[Field1]=" & "'" & Me![Field1] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

However, when I run this it keeps prompting me to specify the value of Field1 so this value is obviously not getting through. Do you have any idea why this might be happening?

Thanks in advance
Kabir

View 4 Replies View Related

Passing Several Parameters To Subform

Dec 22, 2006

Hi,

I would like to transmit several parameters from my main form to the subform when I open it.

Parameters could be used in the subform by onload event, for eample, to define form caption, hide or show buttons, enable or disable edit boxes, give them a color, ... It could also allow to use the same form in different application contexts, which would reduce so the development time.

More than one technique might be possible.
I used the following one :
- I put the parameter value I want to pass into myParameter
- when click on the button to open the subform :
DoCmd.OpenForm myDocument, acNormal, , , , , myParameter
- when loading the subform, retreive the parameter value in Me.OpenArgs and using it (eg disable a button)

It works fine. But I can pass only a single value with this technique and it's not enough. I tried to give an array as myParameter and fill it with my parameters values, but Access refuses an array to be in the DoCmd statement for OpenArgs option.

Any idea about passing several parameters to the subform ?
Or may be an alternative to the DoCmd technique ?

Thanks.

View 5 Replies View Related

Passing Parameters From Form To Queries

Mar 23, 2006

Good Afternoon,

I am trying to create a form where a user will enter in a value into a text field. Afterwards, when the user clicks "Enter", a query will run and will LOOK FOR THE VALUE THAT WAS ENTERED INTO THE TEXT FIELD. i.e.
User enters their address into the field and clicks the enter button.
Afterwards, a query will run like
select * from customers where address = @address <== the value the user entered into the text field. This is where the mystery lies. How do you pass values?????

Thanks,
Nervous Jervous

View 6 Replies View Related

Passing Parameters From Excel To An Access Query

Jun 4, 2007

Hey folks,

Not sure if this is the best forum but decided to put it here anyway.

I have a Access query that reads:

SELECT bleh
FROM blah
WHERE something > 10

Then in Excel I pull the data across using:

Set qdf = db.QueryDefs(qryName)
Set rs = qdf.OpenRecordset

and paste the data using

ws1.Range("IV1").End(xlToLeft).Offset(0, 2).CopyFromRecordset rs

I now want to change the query so the where statement reads

WHERE something > [amt]

So the question is how do I pass the value for the parameter value for [amt] from excel to access?

View 1 Replies View Related

Passing Parameters To A Query From A Form To Filter A Report

Aug 15, 2006

I would like to have a user enter a start date and an end date into two
textboxes on a form. The two dates will be used to query a table. I
would then like to print a report that was created from that query.

Here is the query created as a stored procedure:


SELECT Transactions.*, Hoods.*
FROM Hoods INNER JOIN Transactions ON
[Hoods].[ID]=[Transactions].[BoxID]
WHERE ([Transactions].[Date] Between [@StartDate] And [@EndDate])
ORDER BY [Transactions].[Date];


What would be the best way to pass txtStartDate to @StartDate and
txtEndDate to @EndDate in the VBA code of the form? How would I open or
print the report created from that query filtered on that date range?


Any suggestions? Am I going about it wrong? Should I have created the
report from the above query, or should I do it another way? Can anyone
direct me to some code that does all of the above or something
similiar?


Thanks.

View 14 Replies View Related

Modules & VBA :: Passing Parameters To Report Doesn't Work

Feb 23, 2015

I have a query that sums up the number of parts used. This works fine.

I want to be able to limit this query to parts used after a specific date.

I have in my report

DoCmd.OpenReport "Part Totals Report", acViewPreview, , "[Part Date])>= " & SQLDate

The report is bound to a query that has 2 group by fields, 1 count field a a further field, a date field ([Part Date], that I put a default criteria on. This field is not displayed. If I don't put a criteria on this field disappears when I close and open again.

I pass a date to the program via a form and this ultimately ends up in SQLDate. When I run this I get promted to enter [Part Date] even though I'm setting it equal to SQLDate above. I can out garbage to a proper date in here either way the report picks up the default date entered in by the query.

1. Get rid of all of the parameters off the query.

2. Then you can use the Where Clause of the DoCmd.OpenReport code to specify the parameters based on your variables.

1.Not sure what this means but when I get rid of the criteria for the parameter the field disappears (I'm setting the show field to no as I don't want totals group by date). Getting rid of the field gives me all parts used.

2.I think I'm doing this in the above but will bow to superior knowledge!!

or is it I can't pass a parameter to a report run by a query that is grouping fields together to produce a count.

Incidentally once the report has been run (albeit with the wrong parameters) and I go into design mode and look at the property sheet for the report the correct filter is there (i.e., the date that has been input) but it quite clearly ignores this.

View 1 Replies View Related

Reports :: Navigation Form - Passing Query Parameters To A Report

Aug 4, 2014

I have a navigation form that will have 6-8 tabs. We were using about that many databases, but we are finally consolidating them into one. The result of us using so many databases has been the multitude of forms and reports that were necessary for each database prior to merging them together.

The problem: There will be anywhere from 12-20 (text boxes) that the user can use to search anything in our database. What we need to have happen, if possible, is for those search parameters to show up in the header of our report if they have text in them. If the text box is blank, it should not show up in the header of the report.

I have read how to to do the start/end date technique, but I do not know if that would work for what we are doing since the boxes would only show up if they are populated by the user.

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

Passing Parameters Thru Combo Selection: ERROR:Data Type Mismatch Criteria Expression

Oct 17, 2006

I am trying to pass parameters to my qury thru my combo selection. I keep getting this error "Data type mismatch criteria expression", does anyone have an idea why?
WHERE (((fShiftWorked([tblTimeLog].[timeStart])=[Forms]![frmOperatorWorkDone]![cboShift] Or IsNull([Forms]![frmOperatorWorkDone]![cboShift]))=True));


I have spent so much time onthis already and i am sick of it :mad:


Attached is my db. Please help me out here.

View 2 Replies View Related

Argument Passing

Sep 18, 2006

I have a statemtn like this

DoCmd.OpenQuery("UPD_RECEIPT_IMP")

When I run the above, it pops up the input box for user to key in the argument.

How can I stop this and pass the argument to the query in macro

Need help on this.Thanks...

View 1 Replies View Related

Passing Value To A Sub Form

Feb 26, 2005

Hello,

I have a combo box on a main form and one on a subForm (DataSheet View)...

I want the value in the main_combo to populate the sub_combo for every record in the subform.

I think the code would look like this, but I cant get it to work?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub MAIN_DUNS_AfterUpdate(Cancel As Integer)

Me.CLIENT_DEAL.SUB_DUNS = Me.MAIN_DUNS.Value

End Sub

MAIN_DUNS= Combo on main form
SUB_DUNS= Combo on sub form
CLIENT_DEAL= Sub Form
DEAL_INFORMATION=Main Form
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Any Ideas on how to get this to work correctly??

View 1 Replies View Related

Passing Criteria

Nov 16, 2004

I am using Office/Access 2003. I have created a report that functions fine within access. The report is based on a query requesting the users Representative ID. It functions as expected. We then creayed a web page using the same query. Again this works quite well. The user clicks on the link - Access pops up the criteria dialog asking for the rep id. What our problem is that we are trying to determine where we can put the Rep ID in the page so it will automatically fill in the Criteria Dialog. We see no place in the access page where the criteria can passed. We have the criteria because they use it when they sign in to the sight. I can pass it as a hidden field, an application variable, or even a server variable but how do I get the web page to see it and stuff it into the criteria dialog.

Frustrated in Tucson! Thanks for your help in advance

Greggers

View 2 Replies View Related

Passing Value In One-to-many Relationship

Apr 26, 2005

In my accounting database, I have a form for the requisition and a subform with the line items of the order. When a user has completed their changes, they click a button which closes the form and changes a value in the main table (as in the requisition status is now "submitted" or "approved"). Now I'd like to pass that status value to the line items in the sub-form (based on a different table, of course).

I have another subform that displays the requisition record id, the line item record id, and the status for the line item. In the On Current field of that subform, I pass the value from the main form to the subform. The subform is requeried when the user pushes the button that changes the requisition's status.

The problem is when I have more than one line item for a requisition. The first line item always receives the requisition's status value. Any other line items are not updated. Naturally, if I scroll through the records, they refresh and their status is correctly updated. But this subform won't even be visible to the user, and I certainly don't want them to have to scroll through it anyway. Is there anyway to pass the value to each of the records instead of just the first?

Here is the code I'm using in On Current in my status subform:
Me![process_status_rec_id] = Me.Parent!req_process_status_rec_id

Thanks for your help!

View 2 Replies View Related

Passing Values

Apr 25, 2005

I need to find a way of passing a value from an Access form to an .asp page...

Page1.asp is viewable on the web and asks a user for a code and password - these are checked against a database and when a match is found page2.asp is opened showing values based on SQL views which match the criteria from page1.asp.

What I want to do is be able to open page2.asp from a button in Access - the button should therefore force the opening of page2.asp in a web browser and pass to it the values from that record on the database (code and password).

What code would sit on the button to get it to do this?

View 1 Replies View Related

Passing Parameter

May 23, 2007

i have a working stored proc and a working access pass through query

the below is working in access
exec appcheck @myapp='1'

but i want to point directly to a form

ive tried this but with no success
exec appcheck @myapp=[forms]![frm_test]![pass]


Also i would like to know how to return the results directly into a table?

View 2 Replies View Related

Parameters

Mar 16, 2006

I have created a report from the results of a query. The query has 2 parameters.

SELECT Nonconformances.DateRaised, Nonconformances.Customer
FROM Nonconformances
WHERE (((Nonconformances.DateRaised) Between [Enter start date] And [Enter end date])) OR (((Nonconformances.Customer) Like [Enter customer name] & "*"));

Now the problem is that I have been asked to add the search criteria to the report header. If the search criteria came from a form, no problem, but the user enters the criteria into a parameter box generated by the query. So if the start date was 1/5/05 and end date was 31/12/05 and the customer search was F.C, how do I capture this and show it on the report?

Any help appreciated.

View 10 Replies View Related

Parameters!

Sep 1, 2006

Hi

When I want to run a form it prompts me to enter some parameters. I wonder what could have caused this issue?

Any help will be very much appreciated.
B

View 3 Replies View Related

Parameters

Jun 3, 2005

I have a date field. I have
Between [Please enter second begin date] And [Please enter second end date]
as my criteria so that the user may enter two dates. But, I want the extreme dates to be included in my data.

For Example: If the user enters 1/1/2005 and 1/31/2005, I want the information for the 1st and 31st to be included. How can I do this using just about the same criteria statement?

View 8 Replies View Related

Where Are The Parameters?

Nov 29, 2005

Below is a query in SQL view that is driving me crazy.

When ran it ask for a StartDate, EndDate, StartDate, EndDate.

Can someone please look and see if they can determin where the criteria is coming in from. In design view there is no criteria set up to ask for dates. Also, there is no parameter set in the parameters box.




SELECT tblBooksAndContracts.intTrackingNumber, tblGroupInformation.strGroupName, tblGroupInformation.strGroupNumber, tblSystems.ysnSystemWork, tblSystems.dtmSystemWorkComplete, tblGroupInformation.dtmDateMembershipReceived, tblGroupInformation.strRegion, tblBooksAndContracts.ysnNeedBook, tblBooksAndContracts.ysnNeedContract, tblBooksAndContracts.intBookAndContractCarveOut, CompareDates([tblBooksAndContracts].[dtmBookShipped],[tblBooksAndContracts].[dtmASODraftsSent]) AS [Book Complete], tblBooksAndContracts.dtmContractDistributedToMarke ting AS [Contract Complete], CompareDates([tblBooksAndContracts].[dtmBookShipped],[tblBooksAndContracts].[dtmASODraftsSent],[tblBooksAndContracts].[dtmContractDistributedToMarketing]) AS [B/C Complete], ([tblGroupInformation.dtmDateMembershipReceived]+[tblBooksAndContracts].[intBookAndContractCarveOut]+30) AS ECD, CompareDates([tblBooksAndContracts].[dtmBookShipped],[tblBooksAndContracts].[dtmASODraftsSent],[tblBooksAndContracts].[dtmContractDistributedToMarketing],[tblSystems].[dtmSystemWorkComplete],[tblGroupInformation].[dtmDateMembershipReceived]) AS [Master Complete Date], tblGroupInformation.dtmEffectiveDate, tblGroupInformation.strRegion, tblGroupInformation.strNRC
FROM (tblBooksAndContracts INNER JOIN tblSystems ON tblBooksAndContracts.intTrackingNumber = tblSystems.intTrackingNumber) INNER JOIN tblGroupInformation ON (tblSystems.intTrackingNumber = tblGroupInformation.intTrackingNumber) AND (tblBooksAndContracts.intTrackingNumber = tblGroupInformation.intTrackingNumber)
WHERE (((EntryIsComplete([ysnSystemWork],[dtmSystemWorkComplete],[ysnNeedIDCard],[dtmMailIDCards],[ysnNeedBook],[ysnNeedContract],[ysnNeedDraft],[ysnNeedFlyer],[ysnBookAndContractComplete]))=Yes) AND ((IsBetween([startDate],[endDate],[tblBooksAndContracts].[dtmBookShipped],[tblBooksAndContracts].[dtmASODraftsSent],[tblBooksAndContracts].[dtmContractDistributedToMarketing],[tblSystems].[dtmSystemWorkComplete],[dtmMailIDCards],[tblGroupInformation].[dtmDateMembershipReceived]))=Yes));


As well as when it does run, and you enter the span dates, if the field is blank it inputs 12:00 am in the field and includes it in the query. I checked the tables and it is not set up to input 12:00 am as a default value, nor is it stored as 12:00 am in the tables.

I am at my wits end here and any help/advice would be helpful.

If this does't make sense let me know and I will try and explain further.

Thanks in advance!

*please disregard the grammer, I am typing this fast before I head out to get the kids..a mommies job is never done!*:eek:

View 10 Replies View Related

Too Few Parameters.

Sep 21, 2006

Please look at this sql statement and tell me where the error is. When I try to open the recordset, I get a "Too few parameters. Expected 1" error. That kind of error usually goes with missing # on dates or ' on text

DateTime is a DateTime field that defaults to Now().

The problem appears to be in the dates because when I comment out all after the user parameter, it works, and taking out the "AND Used Is Null" doesn't help.

sqlstr = "SELECT * " & _
"FROM tbl_Usage " & _
"WHERE User = '" & UsrNm & "' " & _
"AND DateTime >= #" & Date & "# and DateTime < #" & DateAdd("d", Date, 1) & "# AND Used Is Null"

This is from the immediate window
?sqlstr
SELECT * FROM tbl_Usage WHERE User = 's5ucba' AND DateTime >= #9/21/2006# and DateTime < #9/22/2006# AND Used Is Null

View 1 Replies View Related

Parameters

Sep 4, 2007

Hi

I am using 'Like "*" & [Forms]![Template]![Combo433] & "*"' in a query to a combo box on a form so if I have nothing selected in the combo all data is shown, except this does not show any null values!

Can any advise on how I can adapt this to allow for null values!

Thanks in advance...

View 1 Replies View Related

Parameters Etc

Dec 25, 2007

I have designed an access database for an organisation. The database is basically all the people who work for an organisation, their addresses, the borough they work in and other details. I have deisgned a query that picks out all the people who work in a particular borough, by using parameters. So when I click a button, a box comes up and asks me to put in the borough and voila, I get a list of all the people who work in that borough. But what do I put in the parameter box, if I want the entire list of people in all the boroughs not just one particular borough?

Really appreciate the help...

View 1 Replies View Related

Parameters

Jun 13, 2005

I have a form that lets the user enter a beginning date and ending date in text boxes, then below that asks the user to choose a major category from a combo box. That works fine. The user the hits a command button below which opens a report. On the report is a chart based on the information they provide. This works well too. Also, the heading of my report contains the parameters in which the user gave to develop the report. The dates come up fine because I used a text box and put in =[Forms]![myformname]![parametername].
But this code does not work for a combo box. It will not pick up the choice that the user makes. Does anyone know how I can capture the answer so that I may display it in my report?

View 1 Replies View Related

Parameters

Feb 15, 2007

How would I go about creating a parameter that can search for all events that occurred in a particular month. I don't want the user to have know the exact date, just the month and year.

View 1 Replies View Related







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