Solved

msaccess 2007 creating a "variable"

Posted on 2013-02-05
5
226 Views
Last Modified: 2013-02-05
Hi.

I have a database with a lot of dates in it and I would like to create an input form that has a field or variable called date which I enter and then a query will display all the records in my table corresponding to that date. I know I could do this in a report but the query I will make will also update the date by 7 days. How do I get from the input form to the report to print out a simple query like this.?
0
Comment
Question by:PawloA
  • 3
  • 2
5 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Not sure about the "update" part, ...but to have a form variable used as a query criteria you can:
1. Create a public Variable in a module:
Public dtmYourDate as date

2. Create a public function to retrieve this date:
Public Function GetYourDate() as date
    GetYourDate=dtmYourDate
end function

Then create your query to look at this variable as the criteria:
SELECT....
FROM...
WHERE Yourdate=GetYourDate()

Then assign the form control value to the variable
Create a button to open the query
On the click event of the button, use code like this:
dtmYourDate =txtYourDate
Docmd.OpenQuery "YourQuery"

;-)

JeffCoachman
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
Comment Utility
like so...
Database87.mdb
0
 
LVL 1

Author Comment

by:PawloA
Comment Utility
How would I do this in Access. do I go to the visual basic. Sorry I am pretty new to msaccess and I have to take a crash course on this. Any help would be appreachiated.
0
 
LVL 1

Author Closing Comment

by:PawloA
Comment Utility
Thanks. This is exactly what I am looking for.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
;-)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now