473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

refering to variable in a form.

I have a form that the user enters a financial quarter and year to produce a report. the report is based on a query that uses the quarter and year. seems simple enough. The financial quarter and year are drop down boxes. When the run query button is pushed the form concantinates the strings QueryStartDate and QueryEndDate. How do I refer to these variables in my query expression?

Public Sub Preview_Report_Click()
On Error GoTo Err_Preview_Report_Click

Dim stDocName As String
Dim QueryEndDate As String
Dim QueryStartDate As String

If Me.Quarter = 1 Then
QueryStartDate = "01/01/" & Me.Year
QueryEndDate = "04/01/" & Me.Year
ElseIf Me.Quarter = 2 Then
QueryStartDate = "04/01/" & Me.Year
QueryEndDate = "07/01/" & Me.Year
ElseIf Me.Quarter = 3 Then
QueryStartDate = "07/01/" & Me.Year
QueryEndDate = "09/01/" & Me.Year
ElseIf Me.Quarter = 4 Then
QueryStartDate = "09/01/" & Me.Year
QueryEndDate = "12/31/" & Me.Year
End If
stDocName = "QuarterlyTestReport"
DoCmd.OpenReport stDocName, acPreview

Thanks in advance
PS if there is a simpler way to do this I would like to know.
Feb 10 '08 #1
2 1214
MMcCarthy
14,534 Expert Mod 8TB
You don't reference them in your query expression. You set them as criteria in the OpenReport function.
Expand|Select|Wrap|Line Numbers
  1. Public Sub Preview_Report_Click()
  2. On Error GoTo Err_Preview_Report_Click
  3.  
  4.     Dim stDocName As String
  5. Dim stLinkCriteria As String
  6.     Dim QueryEndDate As String
  7.     Dim QueryStartDate As String
  8.  
  9.     If Me.Quarter = 1 Then
  10.         QueryStartDate = "01/01/" & Me.Year
  11.         QueryEndDate = "04/01/" & Me.Year
  12.     ElseIf Me.Quarter = 2 Then
  13.         QueryStartDate = "04/01/" & Me.Year
  14.         QueryEndDate = "07/01/" & Me.Year
  15.     ElseIf Me.Quarter = 3 Then
  16.         QueryStartDate = "07/01/" & Me.Year
  17.         QueryEndDate = "09/01/" & Me.Year
  18.     ElseIf Me.Quarter = 4 Then
  19.         QueryStartDate = "09/01/" & Me.Year
  20.         QueryEndDate = "12/31/" & Me.Year
  21.     End If
  22.     stDocName = "QuarterlyTestReport"
  23.     stLinkCriteria = "[DateField] BETWEEN #" & QueryStartDate & "# AND #" & QueryEndDate & "#"
  24.  
  25.     DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
  26.  
Feb 10 '08 #2
Thanks that worked perfectly
Feb 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: news.versatel.de | last post by:
Hello NG, I am using javascript to open a new window like this: printpreview=window.open('printview.php','printprev','width=600,height=600'); The new window has a layer called preview: ...
1
by: David B | last post by:
I have a sub form in datasheet view on a form. I want a query to find the recordid every time a different row on the datasheet has the focus. The query is grabbing data for a combo on a second sub...
3
by: Kranman | last post by:
Hi All, Love this site, have gotten a lot from it. This is my first time posting though, so forgive me for any errors. I have an Access 2000 db where I have a main form of Contractors and on...
4
by: Terri | last post by:
Main form-frmCheckRequest Sub form-subfrmCheckRequestPayments On my subform I have 2 fields FundCode and ClassNumber. Both are comboboxes. I'm trying to filter ClassNumber based on FundCode. ...
5
by: Rick | last post by:
Hi, Another question for today, it's about structs refering to each other. I tried this code struct List; struct child { struct List parent; };
2
by: D Miller | last post by:
This might be a pretty basic question... How do I refer to a control by name as a variable? For instance I have 90 controls is a row named C1 though C90 and I want to have focus shifted from...
4
by: rhc | last post by:
access 2000 I have a tab control with 2 pages and one subform on each. On parent form P from the form_current() event of subform A I cant seem to refer to subform B. msgbox forms!.form.name...
1
by: Sarwan | last post by:
Hello everybody I have a solution in which there is an unmanaged MFC application. Then i added a new managed .Net Windows Form application. I was trying to refer an header file of unmanaged...
5
by: Walter Konopacki | last post by:
Have a client form with an address sub form. I then open a jobs form and want to display the name and address on the jobs form. No problem with the name which is in the clients from which is the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.