Forms :: Using A Variable From A Form To A Query As A Criterion?

Feb 23, 2015

I want to use a variable from a form to a query as a criterion. but how?

View Replies


ADVERTISEMENT

Forms :: Opening A Form And Displaying Records Based On Two Criterion

Feb 24, 2014

OK, I have two forms:

Form 1: Courses

Form 2: Mark Grid

The user select the class from [Combo28] for the unit already in [Textbox named Unit] from Form 1 and wants to list all the students for that particular class and unit in form 2.

I have tried god knows how many different codes. I've been playing with:

DoCmd.OpenForm "Mark Grid", , , "[Text43]=" & Me![Combo28] & " AND [Text17]= '" & Me![Unit] & "'"

But with no luck.

View 2 Replies View Related

Query Criterion Question

Sep 15, 2005

Ok, I made a query that returns a Case Manager, their associated cases, and 3 dates that relate to each of these cases. So its:

Case Manager-----Case Name----Date1-----Date2-----Date3

I only want records to appear that have a value in at least 1 of the 3 date fields. If they have no data in ANY of the date fields I want those records excluded. How do I build this?

View 3 Replies View Related

Queries :: Using IIf Statement In Query Criterion

Jun 5, 2015

I'm trying to use IIf in a query criterion, but not having any luck.

I have a field called 'ayr_code' which has values in the format:2015/6

2014/5
2013/4
2012/3
2011/2
2010/1
2009/0
2008/9

I want to return all records where in this field:if the current month is November or December, the first four characters of 'ayr_code' are between five years ago and the current year;

If the current month is between January and October, the first four characters of 'ayr_code' are between six years ago and last year;

So, in October 2015, I'd like to see records with an 'ayr_code' of 2014/5, 2013/4, 2012/3, 2011/2, 2010/1 or 2009/0. In November 2015, I'd like to see records with an 'ayr_code' of 2015/6, 2014/5, 2013/4, 2012/3, 2011/2 or 2010/1.

I've tried to do this using solution one below, but this is not working. I've gone for solution two, but I'd like to know why solution one doesn't work and if there is a way to amend it so that it does.

Solution one [preferable; not working]

Create the following field:

Code : Expr1: Left([cam_sas.ayr_code],4)

Add the following criterion:

Code : IIf(Month(Now())>10,>=Year(Now())-5 And <=Year(Now()),>=Year(Now())-6 And <=Year(Now())-1)

So this should get the first four characters of 'ayr_code' then apply one of two criteria on the results based on whether the current month is after October or not.

Solution two [non-preferable; working]

Create the following field:

Code : Expr1: IIf(Month(Now())>10,Left([cam_sas.ayr_code],4),Left([cam_sas.ayr_code],4)+1)

Add the following criterion:

Code : >=Year(Now())-5 And <=Year(Now())

This takes the first four characters of 'ayr_code' then if the current month is not after October it adds one to the result, after which it applies the criterion that the final output must be between this year and five years ago.

View 8 Replies View Related

Forms :: Using Variable For Form Name?

Feb 21, 2014

Is there a way to use a variable instead of a form name?

e.g. FRM1 is a form

Forms![FRM1]!textbox1.SetFocus

Instead of FRM1 , a variable is used which can be any other form name.??????

View 10 Replies View Related

Forms :: Displaying Variable On A Form?

Aug 28, 2013

I have been given a form that you pass a parameter into and on the basis of this it performs certain amendments to the particular data AND also runs 2 stored procedures on this data. I need to get the data to display on the form so that the user can visually verify if it is the correct data and then they will on click to execute the amendments and stored procedures.

I cannot get the data to display on the screen? I have tried to create a variable in the VBA code to store the data in and then used a message box to try to display it but to no avail?

View 3 Replies View Related

Forms :: Use Query Name Variable Instead Of Contents Of Name

Apr 19, 2014

I have defined a recordsource based on a predefined query. Now I intend to use the SQL statement which works to produce other recordsources based on other queries. More concretely here is my code as of now:

Code:
Dim J1 As Long
Dim SQLRecordSource As String
J1 = Forms(ParName).MemID
SQLRecordSource = "SELECT DISTINCTROW [MembersTbl].* FROM [MembersTbl]" & _
"INNER JOIN [ActiveMembersQy] ON " & _
"[MembersTbl].[MemID] = [ActiveMembersQy].[MemID] " & _
" WHERE [ActiveMembersQy].[MemID] = " & J1 & ";"

In the future instead of writing it like this:

Code:
Select Case QryName
Case "NonMembersQy"
SQLRecordSource = "SELECT DISTINCTROW [MembersTbl].* FROM [MembersTbl]" & _
"INNER JOIN [NonMembersQy] ON " & _
"[MembersTbl].[MemID] = [NonMembersQy].[MemID] " & _
" WHERE [NonMembersQy].[MemID] = " & J1 & ";"

[Code] ....

I wish to write it like this (which does not work):

Code:
SQLRecordSource = "SELECT DISTINCTROW MembersTbl.* FROM MembersTbl" & _
"INNER JOIN QryName ON " & _
"MembersTbl.[MemID] = QryName.[MemID] " & _
" WHERE QryName.[MemID] = " & J1 & ";"

Is this possible ie put the name of the variable that holds the name of the query in quotes or sometimes put the name of the query instead of the contents of the name. If there is a contents function for variables in VBA that can be used by I doubt whether it exists.

View 3 Replies View Related

Forms :: Display A Public Variable On A Form

Apr 3, 2013

I am working on a database where I want some specific information displayed on a form, preferably on the form header. I want to display this on all of my forms. In a standard module, I have a code segment that runs a query returning values, and I assign those values to my public variables. I run this code segment triggered by "on activate" of each form.

The variables contain an Event Date, and an Event Name. I want this information to appear on each form. How do I get this data onto my form as part of the form header, or if cannot put on header section, then in the detail section?

View 2 Replies View Related

Form Variable Passed To Query

May 7, 2007

Not sure if I am asking the right question, but....

I would like to pass a string variable to a query but it does not seem to work.

In the query, my criteria for the date field is (and works):

>=[forms]![frmDisposition]![FromDate] And <=[forms]![frmDisposition]![ToDate]

But, this is not working for the ID field criteria:

[forms]![frmDisposition]![ID]

In the forms code, I have a string based on the result of 3 check box. I tried using an unbound (ID) control to display the string so I know that the value of the string is correct. EX: "FW" Or "MA" Or "PD"

Is it possible to pass the value of the string to the query or do I need to try and pass the value of the unbound control to the query?

View 6 Replies View Related

Forms :: Writing Data Into Text Boxes On A Form Using Variable In Name

Jan 29, 2015

I'm trying to write code which writes text into text boxes on a form depending of certain content of other text boxes. The names of the text boxes are all very similar

F.i. R1, R2, R3 ...... R12 if the content of these boxes are empty then the content of the corresponding text boxes VR1, IR1, VR2, IR2, VR3, IR3.......VR12, IR12 should also be empty.

In fact I am trying to write something like this

DO UNTIL i=12
if me.R(i).value = "" then
me.VR(i).value = ""
me.IR(i).value = ""
endif
LOOP

But this isn't working. The solution below works but isn't a very nice one, writing 12 times the same code

if me.R1.value = "" then
me.VR1.value = ""
me.IR1.value = ""
endif

if me.R2.value = "" then
me.VR2.value = ""
me.IR2.value = ""
endif

View 4 Replies View Related

Forms :: Adding Variable To Specific Row Of Listbox (Table / Query)

May 31, 2014

The VBA code I have at the moment:

me.Results.Rowsource = "SELECT car, title, FROM dbo_inventory"

Is it possible to add a variable to a specific row in listbox using the code above? In this case the price?

View 3 Replies View Related

Pass Variable To Form And Decide Which Query

Aug 15, 2006

Is it possible to pass a variable to a form when a checkbox is clicked?
I have 8 tabs, each of which has a checkbox.
When a checkbox is clicked, I would like it to display 1 form but that form should display different data each time by either running a SQL query with specific variables passed to it or by running a different SQL query.

?

View 1 Replies View Related

GROUP BY Just One Criterion

Jun 11, 2005

I need to execute this query from an ASP . Net page. I'm connected to an Access 2002 DB.

SELECT tblBudget.GroupCode, tblBudget.GCDescriptioon, tblBudget.Amount
FROM tblBudget
GROUP BY tblBudget.GroupCode, tblBudget.GCDescription, tblBudget.Amount
ORDER BY tblBudget.GroupCode;

If I delete tblBudget.GCDescription and tblBudget.Amount from the "GROUP BY" instruction it does not work.

What I want to do is that in case tblBudget.GroupCode is repeated (e.g. several records with the same group code) I want to display only one line summarizing all info for the given group code.

Thank you

View 1 Replies View Related

Parameter Criterion Not Working

Feb 7, 2006

Hi to all

I am setting up a query to report on the turnaround time for appication to be processed.

I have a calulated column to calulate the numbe rof days betwen receipt and approval of applications. I now want to be able to run the query and subsequently the report by having a prompt to enter anlower and upper number of days range.

I have used the experssion Between [Lower range] and [ Upper range] to prompt and when I enter say 1 to 5 days the query returns all days.

Any thoughts as to why it is not working and what can I do differnetly?

Regards

mgerada :(

View 6 Replies View Related

Using Criterion To Add Begin/end Date Range. How Get On Report

Mar 26, 2007

I am using a simple " >= [BeginDate:] and <= [EndDate:]" in the criterion section of a query to allow a date range to be selected in the query which is used in a report. How can i get that [BeginDate:] and [EndDate:] info available to print on the report so it shows the actual date range being displayed in the report ? thanks.

View 2 Replies View Related

Reports :: Subform Field Linker Error - Obj Variable Or With Block Variable Not Set

Apr 16, 2013

I am creating a 2 level report to confirm an order. Main report already created, runs successfully called as subform/subreport under "OrderDetails" form. Linked to master using Order.ID. There are two versions of the confirmation report that have different layouts for different program types.

The hangup comes when I try to add a "Class Dates" subreport. It lists dates of individual classes and Skip dates. I have created the subreport as "srClassDates". When I add it to the main report, it lists the records. However, when I try to link it to the Main report, an error message box appears with the "object variable or With block variable not set".

I have tried rebuilding both the main and subreports, rebuilt the query, have not found anything that changes the result.

Linker has been working successfully on other subforms. Report with groupings works fine, but I need data from 2 tables both linked to order.id.

View 2 Replies View Related

Modules & VBA :: Error 91 - Object Variable Or With Block Variable Not Set

Jul 8, 2013

Error 91 - Object variable or With block variable not set

I am getting this error telling me that an object variable is not set.

I know which variable it is but when I step through the debugger it sets the variable and all is fine? Issue is that public variable of a class is not getting set when the VBA Editor is not open?

View 14 Replies View Related

Modules & VBA :: Sorting / Object Variable Or With Block Variable Not Set

Oct 3, 2014

This code runs fine the FIRST time, however trows up a message the SECOND time it is run.

The error is on the line ".Range"

I am trying to sort records which have been exported to Excel.

Dim LR As Integer
LR = 5
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set wbRef = xlApp.Workbooks.Add
With wbRef

wbRef.Activate
.Worksheets("Sheet1").Activate
With ActiveSheet
.Range("A2", .Cells(LR, "O").End(xlUp)).Sort Key1:=.Range("C2"), Order1:=xlAscending, Header:=xlYes
End With
end With

View 3 Replies View Related

I've Never Passed A Variable Between Forms... This Is A First!

Jun 10, 2005

:D
I have a form set up where a user chooses a page tab. Either statistical reports or detail reports. Then they have to choose between 2 toggle buttons. Candidate or hire.

So a user chooses detail, then candidate. An option group below that shows the different groupings of detail candidate reports that they can choose.

A couple of examples - detail report of candidates by office applied to, department, application source etc.

Once that is chosen a button is visible to continue. Now they are taken to the appropriate form. This is done by a global variable gstrformname defined in the afterupdate of the group option that they chose (office etc.)

Once they click to continue to the criteria form, they are choosing the criteria. (for example purposes) the choice below takes the user to a criteria form for choosing an application source ( email, monster.com etc) or click a button and all types are given. I have all of that set up. But now I want to change what report the command button is opening, to a variable. A variable that would be set by the below form when the type of report and grouping for the report are chosen...that defines a certain report.

I specified on this main report menu that it is a candidate report that I want, but when I get to the criteria form, I need a way to pass that choice on. I am not sure how to best do that.

I am trying to avoid making 2 copies of the same form 1 for candidates and 1 for hire. :crazy: I undertstand that I should pass a variable here.

So basically on the main form they choose candidate or hire report, then they choose group. The grouping information tells the command button what form to open (the application source criteria form, the office criteria form, etc). The thing is, this form is the criteria for the candidate report and the hire report. The command button on the criteria form would ideally be -

docmd.previewreport gstrreportname, acpreview

my question is, how or where do I define, from the point that they choose candidate or hire, to the next form, that they want the candidate by office or hire by office report? (define the gstrreportname variable as one of those too.)

Make sense?

Here is a pick of the report form (menu)
http://www.geocities.com/misscrf/reportmenu.jpg


For the afterupdate of the frame for the grouping of the report, I have a select case. In that I define gstrreportname for the report it is, if the choice goes right to a report. If it goes to a form first (for criteria), I define that form with a global variable gstrformname. Can I also define the report there (gstrreportname)? If I do that, will the criteria form know that? Even if I close the main report form?


I hope someone understands me! :shrug:

View 5 Replies View Related

Passing Variable Between Forms

Aug 8, 2006

Hi Everyone,

I'm trying to pass a variable called MyFilter between forms but am having problems. I have created a Module and declared MyFilter as a public string.

The original code in my first form is:

Private Sub Command65_Click()
Dim MyFilter As String
If Me.Filter = "" Then
MsgBox "Please apply a filter to the form first."
ElseIf Me.Dirty Then
' Make sure the record is saved
RunCommand acCmdSaveRecord
Else
MyFilter = Me.Filter
DoCmd.OpenReport "Temp", acViewPreview, , MyFilter

End If
End Sub

How to I change this so that it now stores the value in the Public variable instead of the Private one which it is doing above?

Thanks,

View 5 Replies View Related

Forms :: Using Variable As Fieldname?

Aug 8, 2013

I have a form with 48 unbound text fields name txt1 to txt48.

These are to represent 24 hrs in half hours, to visually represent the hours capacity of my workshop. Now if I choose a date, which is say Monday, I check my settings, and see that the workshop has a capacity of 15 hrs on a monday. Now I would like to in a loop set the backcolour of the remaining fields to red.

Something like for I = 15 (workshop capacity) to 48

me."txt" & I.backcolour=1111
next I

View 3 Replies View Related

Modules & VBA :: Update Contents Of Variable But Not The Variable Itself?

Aug 20, 2014

I look at a lot of files to see when they were last updated. I wanted to write a generic procedure to manage that so ..

Code:
Public fDate As Variant
Public vField As String
Public vFile As String

'GTSdata
vField = "txt_gts_data"

[Code] ....

What I hoped Me.vField would do is update the date field [txt_gts_data] on my form with the date the file was last saved.

i.e. me. txt_gts_data = fDate

What actually happens is the variable vfield gets updated from "txt_gts_data" to 19/08/2014 then later code falls over because the fieldname is lost .

Me.[vField] corrects itself to me.vField (and does not work)
Me!vfield falls over (cannot find the field vField, not surprising J)

How do I say update the contents of the variable, not the variable itself?

View 7 Replies View Related

Reports :: Object Variable Or With Block Variable Not Set

Apr 15, 2015

Runtime error '91'

Running Access 2010.

I have two reports running off of the same crosstab query. I copied one report to make the second report, then modified the second report to change the background of column fields satisfying certain conditions. These lines of code were added to the Detail_Format section, in color below. The report with the extra code lines does not error--the original report errors.

Code:
Option Compare Database
' Constant for maximum number of columns EmployeeSales query would
' create plus 1 for a Totals column. Here, you have 9 employees.
Const conTotalColumns = 11

[Code] .....

If I say OK (rather than debug) after the error message, I can then click the button for the report again and it runs without complaint. And, as I said, the report with the added code never errors.

View 4 Replies View Related

Forms :: Global Variable Not Available When Needed

Oct 21, 2013

I have this declaration in a module called Global Code
Option Compare Database
Public currentCustomerId As Long
Option Explicit

There is one report that simply prints a the firstname of current customer and the amount of each of his invoices.
The current displayed customer's ID is always copied into the variable currentCustomerId.
Below is the SELECT code of the data source of the report.
But whenever I open this report it asks for currentCustomerId.
Is my decalartion not global enough?

SELECT tblCustomers.FirstName, tblInvoice.Amount, FROM tblCustomers INNER JOIN tblInvoices ON tblCustomers.CustomerID=tblInvoices.CustomerID WHERE tblInvoices.CustomerID=currentCustomerId;

Note: I chose to save the current customer's ID in a global variable because, for some reason, when I select the report the Customer form loses the current customer record and goes to the end of the table as if creating a new customer record. This would not be an issue as long as I can retrieve the value in a variable.

View 4 Replies View Related

Modules & VBA :: Sharing A Variable Between Two Forms

Sep 28, 2014

Is this how to share a variable between two (2) forms ?

Form #1
Form1_Popup
Public Var1 As Integer

Form #2
Form2
Public Var1 As Integer
GotIt = Var1

View 4 Replies View Related

Forms :: How To Call A Function From A Variable

Apr 5, 2014

I have the following in Form and it works OK

Call RunForm("frmProviderLookup", "", "Edit", "", "", "Normal", "Normal")

I want to build a combo box with several different RunForm variations as follows:

RunForm("frmProviderLookup", "", "Edit", "", "", "Normal", "Normal")
RunForm("frmCustomerLookup", "", "Edit", "", "", "Normal", "Normal")
RunForm("frmVendorLookup", "", "Edit", "", "", "Normal", "Normal")
etc, there are many of these

When I select one the variations from the combo box the RunForm statement is stored in strAction varaible..How do I code the Call strAction line? (I want only one call statement).In other words how to call a Function from a variable...The start of my module Function works OK and looks like this:

Public Function RunForm(FormName As String, _
Optional WhereCondition As String = "", _
Optional xMode As String = "", _
Optional filterName As String = "", _
Optional Args As String = "", _
Optional WindowMode As String = "", _
Optional View As String = "")

' Parameters (all optional except parameter 1)
' 1 - Form Name
' 2 - Where condition
' 3 - Mode [Add, Edit, View(Read Only), ""(PropertySettings), DS(Datasheet Edit)]
' 4 - Filter Name
' 5 - Opening Arguments
' 6 - Window Mode
' 7 - Form View

View 1 Replies View Related







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