Parameter Control With VBA
Aug 23, 2006How can you control SQL statement parameters with VBA? The SQL statement will not accept a variable.:confused:
View RepliesHow can you control SQL statement parameters with VBA? The SQL statement will not accept a variable.:confused:
View RepliesI can't figure out how to further explain what i needed to do. I hope the attached file could solve my issue.
Thanks for your time!
Sheila
i have a question concerning setting of parameters in a query:
I have a query with a parameter and a form with a control ... however, i want the value of the control to be used as parameter in the query.
For example a checkbox "chkb". Now i specify a query as RecordSource (or ...set ... i'm not sure) for a subform and i want it to change the parameter-value with the value of "chkb".
Is it just necessary to assign the name of the parameter correct (in the query-definition, put smth like [Me].[chkb].[Value]), or do i have to set the parameter in VBA ? And anyway, is it clear what i mean ?
I have a pop up form that is run by a query that needs to grab the parameter value from a field on the open form. It grabs the value for "QuestIDfrm" from the form "frmQuestionDetail" using the statement below pasted into the query parameter.
Code:
[Forms]![frmQuestionDetail]![QuestIDfrm]
This works fine when I call the pop up from the form "frmQuestionDetail". What if I want to call this same pop up form from another form that has the same control (QuestIDfrm).
Is there a generic syntax that would grab QuestIDfrm from the current open form? Something like
Code:
[Forms]![CurrentOpenForm]![QuestIDfrm]
I have a Parameter form which provides various parameters to my queries. The Parameter Form has a Combo box with a list of 50 health facilities which the user can select according to their needs.
There are instances when a user needs data from just one health facility and at times the data is needed for all the 50 health facilities in the district.
How do i address both needs without having to keep adding and deleting the criteria in the underlying queries?
I have added the 'if' condition below in the queries criteria so that if the user does not enter a facility in the combo box, it runs all facilities and if they enter a facility name then the data in the reports is limited to that health facility.
IIf(IsNull([Forms]![Parameter Form]![Combo27]),"",[Forms]![Parameter Form]![Combo27])
It does not work.
Is the expression or VBA code supposed to be entered in the Query or in the Parameter form and how do I make it work?
I have a text box in a report, with it's control source property set to =[BegDt].
Upon loading the report a message box pops up and asks the user for the value of [begDt]. This occurs 3 more times for 3 other parameters.
Now I want to change the design of the report so I decided to put these 4 parameters on a form so the user can fill in the 4 values all at once rather than responding to 4 message boxes that pop up when you run the report.
The problem is now the control source properties in all the different text boxes need to be changed to [forms]![frmABC]![txtBegDt] etc.etc. There are over 100 text boxes in this report that make reference to the 4 different parameters.
Is there a replace command I can use to change all the occurrences in the text boxes or perhaps a simpler way would be to pass the values to the report through code.
I tried placing this in the report header's format event and it doesn't seem to have any effect.
Code:Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)begytd = [Forms]![frmABC]![txtStDt]endytd = [Forms]![frmABC]![txtEndDt]curmo = [Forms]![frmABC]![cboMo]curyr = [Forms]![frmABC]![cboYr]End Sub
I should mention that the report uses a table (tblRecap) as it's record source. I tried using a query that refers back to the form for the parameter values but that means I have to use the query as the reports record source and that creates a problem because the report needs fields from the table to perform calculations.
Can someone help me with a solution please.
Thanks for your time.
I have a form using a query as a control source so that is prompts the user for a parameter when they open the form.
I also have a listbox that is calling the same query.
The issue I am having is when I open the form it will prompt me twice to enter the same parameter.
Tables:
tblship
tblconsignee
tblbill
tblinvoicedetails
Query
qinv
Form
frminvoice
When the user enters the invoice number it populates the ship, consignee, billing address information. I have the list box to display line items for that invoice.
Currently I just have them enter the invoice number twice.
Is there a way I can take the user input and apply it to my other query?
I have a form whose data source is a select query, q3, that is built from 2 other select queries. I'll call them q1, q2, and q3. q1 is a parameter query where I enter a "Cutoff Date" that the 3 queries manipulte and generate the desired results that appear in the form. The problem is that I don't know how to capture the parameter "Cutoff Date" from q1 to display on the form.
View 2 Replies View RelatedI added a new field to one of my tables and query, but when I try to add a control for that field into my form it is not recognising it and the field isn't appearing in the sources for the form, even though the table is sourced to the form? Or am I going to have to do the usual and redo the entire form because I made a minor adjustment?
View 1 Replies View RelatedI have a form with a tab control, inside the tab control I placed an ActiveX control (Microsoft Web Browser). These are at the bottom of the form.
Everything displays fine if the entire form fit on the screen but if the form is too long and I scroll down the browser control is getting obscured by the tab control and getting chopped off (the contents are covered). It is as if the browser control is staying in space where it was and moving behind the tab control as I scroll.
This problem does not occur if I place the browser control directly on the form. Also I note that the browser control is sitting correctly within the tab control.
I have been through all the settings and properties of both controls and haven't been able to fix it. I searched all over the web but no one has previously stumbled across this one by the look of it.
See the attached image ...
I have table that I had to add a new field to which we update with a form. I tried to add a control for the new field but the field does not show up in the list for the control source. I am trying to add a list box to the form with a blank and 5 options.
I have attached screen shots of the table design and the form. The table has the field in datasheet view and I have manually entered a few entries in it but it still will not show in the control source for the form control. The top section of the form is where we enter and select the data for the new records. The bottom section (circled in red) autofills the matching record, from separate tables, for updating with the new entries.
I have added form controls for modified fields in the past so I am confused about why this is happening.
Hi,
I have a query that requires a Start-Date and an End-Date to be input by user for the Where clause. It is asking for both over and over. I've had it ask from 1 up to 4 times! :eek: Shouldn't it store the input and only ask for it once? I'm thinking that the way my query is arranged may be causing it to have to loop through that section more than once to find the data, but that's just my theory. Any help would be great!
Here is my code (abbreviated slightly):
SELECT DISTINCTROW C1.*, C2.*
FROM Pen AS C1 INNER JOIN Jobs AS C2 ON C1.subno=C2.[Jobs Acct]
WHERE ((C1.typ="SS" Or C1.typ="CC" Or C1.typ="PP" Or C1.typ="TT") And C1.stdate>=[Enter Start Date] And C1.stdate<=[Enter End Date] And C2.[Type]<>"EE" And C2.[Type]<>"QQ" And C1.entdate<=C2.[ChangeDate]+60);
I'm selecting rows from "Pen" and "Jobs" that have the same subno/Jobs Acct numbers (text), then there are criteria for "Pen" types, user inputs criteria for date range (Start Date and End Date) and there are criteria for "Jobs" types. Finally, there's a cross-table criteria based on a date field ("Pen" entdate should not be more than 60 days past the "Jobs" ChangeDate). Tables are in quotes in my explanation here.
So running the above, it asks for user input "Enter Start Date", then again for "Enter End Date"...but then it asks for each again...and again...and sometimes again!
Help! :confused:
P.S..I didn't notice this repeating until I made it user input (parameter query) because it was using whatever dates I hard-coded in there before.
OK. I have searched and searched and every thread dances around similar situations but none seem to address this particular one. I am trying to make a control on a sub form visible/not visible depending on the condition of a control on a main form. The catch is that the control I'm trying to change the state of is on a subform located in a tab control. I've tried a thousand combinations and none seem to work. How do I reference the control on the subform in a tab control?
Main Form: frmMemberMain
Tab Control: TabCtl12
Tab Control Page: 2
Subform: frmChildren
Control on subform: txtRelationship
Can someone please help before my brain explodes!! Thanks! :eek:
Hi,
I have reviewed the posts for 'Control Validation' and dowloaded the sample database kindly posted by ansentry.
In the PaymentAmount example, a name has to be entered in the first control before an amount is enterered in the second control. If the controls and tab order are reversed, the validation doesn't work.
I have a form where the 1st Control needs validating before moving on. The code below doesn't work.
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Employee_No) Then
MsgBox "Employee No Required", vbCritical, "Data required "
Cancel = True
Me.Employee_No.SetFocus
Exit Sub
End If
End Sub
Any help greatly appreciated.
John
Hi all,
Can i populate a parameter just like i populate a combo box?
I want to have a FIXED value for parameter. May I know how to do this.
Thank you
Hi,
I am creating a database for work and I keep getting a message that pops up when I opn my form that says "tblClientBFinfo.ClosedReason". Then there is a place to enter a value and and it says "ENTER PARAMETER VALUE." I know it is a problem with one of my tables, specifically the "closed reason" field in the table. But I odn't know why it is asking me to enter a parameter value. Could anyone offer help?
Thanks!
I need a new parameter in my query. When I open the query i need the parameter to be asked in a combo box or drop down box or any way to select the value from the groupo other than typing.
View 1 Replies View RelatedI need a new parameter in my query which enables me to select from a field in the table rather than typing .
View 1 Replies View RelatedI want to run a query automatically in the gotfocus event of a field within a form.
Prior to the gotfocus, a value is entered in an unbound text box on the form and I want to use that value for the maximum value in the parameters. I will set the minimum to zero.
My code errors in the where, it has no problem with the serial number but I can't seem to set the deliv_no to pull the value entered on the form.
SELECT Sum(VOLTEST.unc_del) AS SumOfunc_del
FROM VOLTEST
WHERE (((VOLTEST.SERIAL_NO)=[Forms]![largeVolume1]![serial]) AND ((VOLTEST.DELIV_NO)>0 And (VOLTEST.DELIV_NO)<=([Forms![largeVolume1]![No_del])));
I figure this is a syntax problem. Can you guys see where I have gone wrong?
I need the value to write to the table, not the form when this runs.
Thanks, GG
In my chart I have a yes/no field that I would like to set up a query to for. I want the user to be able to input yes or no and then the data be displayed. Whenever I enter yes or no when the prompt comes up, I get an error saying the expression is typed incorrectly or the data is too complex. How do I set it up so the user can select yes or no in some way? thanks
View 5 Replies View RelatedHi all.I have a form that links to another form using the following macro "[homerid]=[Forms]![Homer Input]![homerid]" so when I click on form 2 the homerid from form 1 is automatically displayed. However on my switchboard I have a direct link to my Form 2 but when I click on this i get a box come up which is titled "enter parameter value" and then the subtitle is "[homerid]=[Forms]![Homer Input]![homerid]", this is fine, but I would like to change the subtitle to something i write myself such as "please enter homerid". Is their a way of doing this? Thanks.
View 2 Replies View RelatedHi,
I have been programing SQL for almost 3 years now but, am a newbie with access. I have just added a field to a form used by employees to enter time and am getting a parameter request when the user clicks Add Entry. I placed a msgBox before the insert line and noticed the field data (type memo) is being sent by the insert query as an integer (without quotes). Any ideas how I might get the insert to pass the Comments field as a string?
Thanks,
~Leo
Private Sub AddTimesheet()
On Error GoTo Err_AddTimesheet
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
'
Set db = CurrentDb()
'
strSQL = "SELECT * FROM tblTimeCard "
strSQL = strSQL & " WHERE [EmpID] = " & Me.cboEmp
strSQL = strSQL & " AND [Category] = " & Me.cboCategory
strSQL = strSQL & " AND [Week] = " & Me.cboWeek & ";"
'
Set rst = db.OpenRecordset( _
strSQL, dbOpenDynaset, dbReadOnly)
'
With rst
If Not .EOF Then
MsgBox ("Time sheet for this employee, category, and week already exists. Please click the record at the bottom of the screen to edit.")
Exit Sub
End If
End With
strSQL = "INSERT INTO tblTimeCard (EmpId, Category, Week, Hours, Comments, CreateDt, CreateID) SELECT "
If IsNull(Me.cboEmp) Then
strSQL = strSQL & "null, "
Else
strSQL = strSQL & Trim(Me.cboEmp) & ", "
End If
If IsNull(Me.cboCategory) Then
strSQL = strSQL & "null, "
Else
strSQL = strSQL & Trim(Me.cboCategory) & ", "
End If
If IsNull(Me.cboWeek) Then
strSQL = strSQL & "null, "
Else
strSQL = strSQL & Trim(Me.cboWeek) & ", "
End If
If IsNull(Me.txtHrs) Then
strSQL = strSQL & "null, "
Else
strSQL = strSQL & Trim(Me.txtHrs) & ", "
End If
If IsNull(Me.txtComments) Then
strSQL = strSQL & "null, "
Else
strSQL = strSQL & Trim(Me.txtComments) & ", "
End If
strSQL = strSQL & "'" & Now() & "', "
strSQL = strSQL & "'" & Trim(Me.txtLogon) & "' "
'Before Insert
MsgBox (strSQL)
DoCmd.RunSQL strSQL
'After Insert
Me.Refresh
Exit_AddTimesheet:
Exit Sub
Err_AddTimesheet:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_AddTimesheet
End Sub
Hello,
I do not know what I did but now when I open my database it asks me over and over again to "enter parameter value" and it won't let me open the database like normal. Please help!
Katie
Set Start & End Dates
I have a list box that lists the 52 week numbers of the year
week 1 being 26-03-2005 to 01-04-2005
week 2 being 02-04-2005 to 08-04-2005....etc.
My aim
By choosing a week no all the records within that date will be returned
I am trying to do away with having to type the start and end date each time a search is carried out
I need to be able to click on the week no and from that the results are shown. perhaps in another list box or something
Any thoughts on how to make this sort of thing work?
thanks
Hello,
I am designing a query as i have been advised in the following Quote:
Doc ManNow, you write a couple of queries. As a parameter to the queries, choose a date that will be your archiving cutoff or split point. Usually the last day of some month or quarter. Doesn't matter as long as you are consistent about it. The technical cutoff will be, in effect, 23:59:59 of the chosen date. The first record to be KEPT will be 00:00:00 of the next day in sequence.
Query #1 - Compute stock on hand as of your cutoff date. Create a single stock-on-hand transaction with the cutoff date. Put it in a temporary table until you need it. This will be a two-layer query. I.e. a query of a query.
Query #1A - a summation query grouped by item number for all transactions earlier than the archiving date so you can get the "inventory of X at archiving date"
Query #1B - an append query that draws from the summation query and feeds it to the temp table. The stock-on-hand record will have the archiving date
.
I am able to get "inventory of X at archiving date" and append the results to a temporary table but I can't see how to append the "archiving Date" data itself to the same table as the "Archiving date" is entered via parameter prompt? Any ideas?
Hi!
When I run a querry I have a parametr querry like this:
Between[FirstDate] and [LastDate]
I want to "catch" the FirstDate and LastDate from the parameter querry and place them in the head of the Report based on the same querry.
How do I do this????