I'm using Access 97 SR-2 on Windows XP to develop an Inventory style database that has some functionality, but having a problem making my query dynamic. I have a switchboard style form which I choose from a selection of 3 command buttons to select a Due Date for record reviews, choices being 30 days, 60 days, and 120 days. When I click on one of the buttons, A public variable, mqryDueDate, is set, for example, to today's date + 30 days, and is of 'Date' type in the declarations. This variable is then used in my query to pull all records which have a due date within the next 30 days. Simple stuff I thought, but the way I have my code and SQL statement, I have no records returned. If I have the query prompt me to manualy enter a date, the correct records ARE returned, but it's when trying to pass the variable data through to the query, nothing is returned. Using the command button's OnClick event, the following (relevant) VBA code is run... -
-
mqryDueDate = Date + 30
-
-
DoCmd.OpenReport "rptDueDate", acViewPreview
-
-
The report's record source is a query called qryDueDate, and contains a SQL statement which is supposed to capture the value of variable mqryDueDate and return records based on.. -
-
WHERE (((AllInstructions.DueDate)< [Forms]![frmReportByDueDate]!mqryDueDate));
-
-
However, no results are returned, and no error is received.
I have had a look at various posts regarding this kind of situation, but no resolve was found. I am suspecting it's that my version of Access isn't able to do this, or I've typed in the WHERE statement wrong.
Any help would be appreciated, and if I've forgotten to provide any information (as per posting guidelines), I do apologise.
thanks...
Should be as simple as this: -
'Set Date
-
Me.txtqryDueDate=Date+30
-
'Open report
-
DoCmd.OpenReport "rptDueDate", acViewPreview
And I was wrong about the # , they are not needed if your using a textbox. - WHERE (((AllInstructions.DueDate)< [Forms]![frmReportByDueDate]![txtqryDueDate]));
9 4155
Is mqryDueDate bound? I suspect maybe if its unbound, access doesn't know that your storing a date type in the field, and formats it as a string instead? (this is just a guess)
You could try: - WHERE (((AllInstructions.DueDate)< & "#" & [Forms]![frmReportByDueDate]!mqryDueDate & "#" & ));
Thanks for quick reply, however, I'm getting a syntax error (missing operator) when I cut and paste the amended SQL statement. I'm sure this is just something silly that I'm missing
Also, the variable is not bound. It's purely a public variable that is used and set only when the OnClick event occurs, and then used for query.
The OnClick vba code is simple only the two lines previously quoted (but obviously with start and end sub and error handler).
If it helps, here is the full SQL statement -
SELECT DISTINCTROW AllInstructions.DocumentNumber, AllInstructions.IssueNumber, AllInstructions.DisciplineID, AllInstructions.DocumentStatusID, AllInstructions.DueDate
-
FROM AllInstructions
-
WHERE (((AllInstructions.DueDate)< & "#" & [Forms]![frmReportByDueDate]!mqryDueDate & "#" & ));
-
and error...
Syntax error (missing operator) in query expressions '(((AllInstructions.DueDate)< & "#" & [Forms]![frmReportByDueDate]!mqryDueDate & "#" & ))'.
thanks...
Is mqryDueDate a variable or a textbox on the form? I dont think the SQL engine can see the variables, even if public (but im unsure, I have never tried)
Well tried setting a public variable for the form, and referencing that from my query, but no such luck. I didn't get any error msg, just no returned records.
I created a unbound textbox (visible=false) and set that using code, then opening query, referencing the Hidden textbox in my criteria, and that worked just fine.
It's a variable. The form has 3 command buttons for selecting a Due Date (and 1 to exit). When the command button is clicked, the OnClick event runs the VBA code to set mqryDueDate to the selected date.
It would make sense to me (disappointingly) that it doesn't work if the SQL engine can't see the variable, and I suppose I'll have to come up with another method of creating a dynamic query for reports.
I may even just have users enter the date manually, not ideal for my purposes, but whatever works will have to do.
thanks...
I'll try using the unbound text box just now and post my result.
thanks...
I created a unbound textbox (visible=false) and set that using code, then opening query, referencing the Hidden textbox in my criteria, and that worked just fine.
I've tried doing this, but it's not working. I do know, however, that it's because I'm not sure how to do this.
If I call the textbox txtqryDueDate, can you provide the code to do this please, and what the SQL query would then be?
thanks...
Should be as simple as this: -
'Set Date
-
Me.txtqryDueDate=Date+30
-
'Open report
-
DoCmd.OpenReport "rptDueDate", acViewPreview
And I was wrong about the # , they are not needed if your using a textbox. - WHERE (((AllInstructions.DueDate)< [Forms]![frmReportByDueDate]![txtqryDueDate]));
Thanks, Smiley. That works ideally!!! :)
When I tried it first time, I missed the "me." when setting the value! yeah, silly, I know. :doh:
thanks...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike Poe |
last post by:
Hi,
Consider the following:
<?
$username = "foo";
$password = "bar";
$host = "db";
|
by: Jerome |
last post by:
Hi,
I've got the following problem:
I want my ASP page to display a certain number (based on a COUNT query),
it works fine if the result is at least 1! If there are no records to be
counted...
|
by: shumaker |
last post by:
I'm wondering how/why this query works. Trying to get my head wrapped
around SQL. Basically the Query deletes from the Import table all
records that are already in FooStrings so that when I do an...
|
by: Matthew Clement |
last post by:
I'm currently building a form (called frmReports) to set the criteria
for a query, but I'm having some trouble with syntax and hope that one
of the guru's here can help me achieve what I'm do.
...
|
by: Michelle |
last post by:
Hi all
I am having problems creating an update query.
I have 2 tables, tblPublishRoster and tblCCAgents_Changed_Shifts.
I want to select all records from tblCCAgents_ChangedShifts where...
|
by: Martin Lacoste |
last post by:
Ok, before I headbutt the computer... don't know why when I add
criteria in a query, I get an 'invalid procedure call'. I also don't
know why after searching the help in access, the various access...
|
by: etwebbox |
last post by:
Hoping someone has some ideas on how to solve this issue:
I have a macro in excel which runs a query against an Access DB (it
actually calls a query inside of Access). The query is not bringing...
|
by: John Baker |
last post by:
Hi:7
Newby here to ASP, and using the ASP.NET Web Matrix development tool. While that tool
looks great for a Newby, I have run into a snag. I have an HTML Text Box which I have
named HireInput,...
|
by: Bob Sanderson |
last post by:
I have a search form from which I hope to be able to select a record by
field JobNumber and display it with an output form titled test.php
<html>
<head>
<title>Job Database Search</title>...
|
by: Matt |
last post by:
I need to add the following variable into an SQL statement and not sure
how to do it.
strGCID needs to be inserted into the following statement:
SQL = "SELECT tblContacts.* FROM tblContacts...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| | |