When attempting to pass date parameters through a form into VBA code, the query contains no records. however, if the values are placed in the query, values are returned, for instance, plugging in -
Between #01/1/2010# And #3/3/2010#
-
instead of the -
Between [Forms]![F_PR_Status]![txb_Start_Date] And [Forms]![F_PR_Status]![txb_End_Date])
-
I would appreciate any guidance.
The following values are being passed through a screen during an event procedure into Access VBA code: -
[Forms]![F_PR_Status]![txb_Start_Date]
-
[Forms]![F_PR_Status]![txb_End_Date]
-
The code that calls this routine is as follows: -
Option Compare Database
-
-
Dim rst As DAO.Recordset
-
Dim rstTemp As Recordset
-
Dim rstSummary As Recordset
-
Dim rstWorkflowLength As Recordset
-
-
-
Dim i As Long
-
Dim dbs As DAO.Database
-
Dim strSQL As String
-
-
Dim strFirstRec As String
-
-
Private Sub Create_Report_Click()
-
On Error GoTo Err_Hndlr
-
-
Call Q_PR_date
-
-
-
Create_Report_Click_Exit:
-
Exit Sub
-
-
-
Err_Hndlr:
-
MsgBox "[" & Err.Number & "]: " & Err.Description, vbInformation, "Create_Report_Click_Exit()"
-
End Sub
-
Private Sub Q_PR_date()
-
On Error GoTo Err_Hndlr
-
-
'**********************************************
-
Dim dbs As Database
-
Dim strSQL As String
-
Dim strQueryName As String
-
Dim qryDef As QueryDef
-
-
Debug.Print Forms!F_PR_Status!txb_Start_Date; " "; Forms!F_PR_Status!txb_End_Date
-
-
If (Eval("[Forms]![F_PR_Status]![txb_Start_Date] Is Null")) Then
-
MsgBox "Please select a Starting Date ", vbInformation, "Required Date"
-
StartingBoardDate.SetFocus
-
Exit Sub
-
End If
-
-
If (Eval("[Forms]![F_PR_Status]![txb_End_Date] Is Null")) Then
-
MsgBox "Please select an Ending Date ", vbInformation, "Required Date"
-
EndingBoardDate.SetFocus
-
Exit Sub
-
End If
-
-
-
'set variable values
-
Set dbs = CurrentDb
-
strQueryName = "sql_PR_date"
-
-
'Delete old query first - we want fresh data!
-
dbs.QueryDefs.Delete strQueryName
-
-
'Notice below how we inserted the variable as a parameter value - Visual Basic will evaluate strMonth and insert the value for us.
-
-
-
strSQL = "SELECT T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date, " & _
-
"Count(T_PRApprovalHistory.Workflow_Step_Date) AS CountOfWorkflow_Step_Date " & _
-
"FROM T_PRApprovalHistory " & _
-
"INNER JOIN tblWorkflowApprovalStep ON " & _
-
"T_PRApprovalHistory.Workflow_Step_Name = tblWorkflowApprovalStep.Workflow_Step_Name " & _
-
"GROUP BY T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date " & _
-
"HAVING (((T_PRApprovalHistory.PR_Date) " & _
-
"Between [Forms]![F_PR_Status]![txb_Start_Date] And [Forms]![F_PR_Status]![txb_End_Date])) " & _
-
"ORDER BY T_PRApprovalHistory.PR_ID, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date;"
-
-
'Create query definition
-
Set qryDef = dbs.CreateQueryDef(strQueryName, strSQL)
-
-
-
Q_PR_date_Exit:
-
Exit Sub
-
-
-
Err_Hndlr:
-
MsgBox "[" & Err.Number & "]: " & Err.Description, vbInformation, "Q_PR_date()"
-
End Sub
-
Copy and Paste this code exactly, and see what happens: - Dim dbs As dao.Database
-
Dim rst As dao.Recordset
-
Dim strSQL As String
-
-
'set variable values
-
Set dbs = CurrentDb
-
-
strSQL = "SELECT T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date, " & _
-
"Count(T_PRApprovalHistory.Workflow_Step_Date) AS CountOfWorkflow_Step_Date " & _
-
"FROM T_PRApprovalHistory " & _
-
"INNER JOIN tblWorkflowApprovalStep ON " & _
-
"T_PRApprovalHistory.Workflow_Step_Name = tblWorkflowApprovalStep.Workflow_Step_Name " & _
-
"GROUP BY T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date " & _
-
"HAVING T_PRApprovalHistory.PR_Date " & _
-
"Between #" & [Forms]![F_PR_Status]![txb_Start_Date] & _
-
"# And #" & [Forms]![F_PR_Status]![txb_End_Date] & "# " & _
-
"ORDER BY T_PRApprovalHistory.PR_ID, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date;"
-
-
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
17 2687 NeoPa 32,556
Expert Mod 16PB
I cannot see why the date literals posted would not work just as well as the date control references ( Literal DateTimes and Their Delimiters (#) may help). However, I can't understand what you're actually asking either, so I'm not sure how to help. What relevance has that great big pile of code got to the situation? No line # references to clarify for a reader where it may fit in.
Try modifying the HAVING Clause, namely: - "HAVING (((T_PRApprovalHistory.PR_Date) " & _
-
"Between #" & [Forms]![F_PR_Status]![txb_Start_Date]" & "# And #" & _
-
[Forms]![F_PR_Status]![txb_End_Date] & #)) " & _
NeoPa 32,556
Expert Mod 16PB
That should work reliably anywhere in the USA. From the linked article though, portable code is achieved by formatting the values explicitly as "m/d/yyyy", assuming of course, that the requirement is to use literals in place of the values already available.
Receiving a syntax error on # added.. -
("SELECT T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date, " & _
-
"Count(T_PRApprovalHistory.Workflow_Step_Date) AS CountOfWorkflow_Step_Date " & _
-
"FROM T_PRApprovalHistory INNER JOIN tblWorkflowApprovalStep ON " & _
-
"T_PRApprovalHistory.Workflow_Step_Name = tblWorkflowApprovalStep.Workflow_Step_Name " & _
-
"GROUP BY T_PRApprovalHistory.PR_ID, T_PRApprovalHistory.PR_Date, tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, T_PRApprovalHistory.Workflow_Step_Date " & _
-
"HAVING (((T_PRApprovalHistory.PR_Date) " & _
-
"Between #" & [Forms]![F_PR_Status]![txb_Start_Date]" & "# And #"[Forms]![F_PR_Status]![txb_End_Date] & #)) " & _
-
"ORDER BY T_PRApprovalHistory.PR_ID, tblWorkflowApprovalStep.Workflow_Step_Order, T_PRApprovalHistory.Workflow_Step_Date;")
The code needs to go as follows: -
Private Sub Insert_Temp_Table()
-
-
On Error GoTo Err_Hndlr
-
'Delete temporary table
-
DoCmd.RunSQL "DROP TABLE tblTemp;"
-
-
'Create temporary table
-
CurrentDb.Execute ("CREATE TABLE tblTemp(PR_Id integer, PR_Date DATETIME, Workflow_Step_Order smallint, Workflow_Step_Name VARCHAR(50), Workflow_Step_Date DATETIME, CountOfWorkflow_Step_Date smallint)")
-
-
'Bind rstTemp to the temporary table
-
Set rstTemp = CurrentDb.OpenRecordset("tblTemp")
-
-
-
'Grab the data and put it in rst
-
-
-
-
Set rst = CurrentDb.OpenRecordset _
-
("SELECT T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date, " & _
-
"Count(T_PRApprovalHistory.Workflow_Step_Date) AS CountOfWorkflow_Step_Date " & _
-
"FROM T_PRApprovalHistory INNER JOIN tblWorkflowApprovalStep ON " & _
-
"T_PRApprovalHistory.Workflow_Step_Name = tblWorkflowApprovalStep.Workflow_Step_Name " & _
-
"GROUP BY T_PRApprovalHistory.PR_ID, T_PRApprovalHistory.PR_Date, tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, T_PRApprovalHistory.Workflow_Step_Date " & _
-
"HAVING (((T_PRApprovalHistory.PR_Date) Between [Forms]![F_PR_Status]![txb_Start_Date] And [Forms]![F_PR_Status]![txb_End_Date])) " & _
-
"ORDER BY T_PRApprovalHistory.PR_ID, tblWorkflowApprovalStep.Workflow_Step_Order, T_PRApprovalHistory.Workflow_Step_Date;")
Your HAVING Clause is NOT what I suggested.
NeoPa 32,556
Expert Mod 16PB
You seem to have ignored my comment too. Maybe you're just not interested in portable code ;)
So sorry guys, i was in the ER last week with a concussion, just getting back to this...will try later this morning. i really do appreciate your guidance.
when the # were added to the code an error was generated: -
HAVING (((T_PRApprovalHistory.PR_Date) " & _
-
"Between #" & [Forms]![F_PR_Status]![txb_Start_Date]" & "# And #" & _
-
[Forms]![F_PR_Status]![txb_End_Date] & #)) " & _
-
What exactly was the Error displayed?
gosh, that was last early week, can't remember, but the original code, the first placed in this forum is working correctly.
Now, it needs to go into a more complex procedure. can this sql statement go into a openrecord statement as shown in the code below. however, it is generating a "data type conversion" error. my guess it is the openrecode statement, any suggestions? -
Dim dbs As Database
-
Dim strSQL As String
-
Dim strQueryName As String
-
-
-
'set variable values
-
Set dbs = CurrentDb
-
strQueryName = "sql_PR_date"
-
-
'Delete old query first - we want fresh data!
-
'dbs.QueryDefs.Delete strQueryName
-
-
strSQL = "SELECT T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date, " & _
-
"Count(T_PRApprovalHistory.Workflow_Step_Date) AS CountOfWorkflow_Step_Date " & _
-
"FROM T_PRApprovalHistory " & _
-
"INNER JOIN tblWorkflowApprovalStep ON " & _
-
"T_PRApprovalHistory.Workflow_Step_Name = tblWorkflowApprovalStep.Workflow_Step_Name " & _
-
"GROUP BY T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date " & _
-
"HAVING (((T_PRApprovalHistory.PR_Date) " & _
-
"Between [Forms]![F_PR_Status]![txb_Start_Date] And [Forms]![F_PR_Status]![txb_End_Date])) " & _
-
"ORDER BY T_PRApprovalHistory.PR_ID, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date;"
-
-
-
Set rst = CurrentDb.OpenRecordset(strQueryName, strSQL)
-
-
You are passing a Query Name and an SQL Statement to the OpenRecordset() Method. This is not how it works - check the Help System for OpenRecordset.
when define recordset as follows, it generates "Too few parameters. Expected 2." -
-
-
Set rst = CurrentDb.OpenRecordset("SELECT T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date, " & _
-
"Count(T_PRApprovalHistory.Workflow_Step_Date) AS CountOfWorkflow_Step_Date " & _
-
"FROM T_PRApprovalHistory " & _
-
"INNER JOIN tblWorkflowApprovalStep ON " & _
-
"T_PRApprovalHistory.Workflow_Step_Name = tblWorkflowApprovalStep.Workflow_Step_Name " & _
-
"GROUP BY T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date " & _
-
"HAVING (((T_PRApprovalHistory.PR_Date) " & _
-
"Between [Forms]![F_PR_Status]![txb_Start_Date] And [Forms]![F_PR_Status]![txb_End_Date])) " & _
-
"ORDER BY T_PRApprovalHistory.PR_ID, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date;")
-
-
if i leave out the following statement it runs, but without the date parameters" -
-
HAVING (((T_PRApprovalHistory.PR_Date) " & _
-
"Between [Forms]![F_PR_Status]![txb_Start_Date] And [Forms]![F_PR_Status]![txb_End_Date])) "
-
-
Copy and Paste this code exactly, and see what happens: - Dim dbs As dao.Database
-
Dim rst As dao.Recordset
-
Dim strSQL As String
-
-
'set variable values
-
Set dbs = CurrentDb
-
-
strSQL = "SELECT T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date, " & _
-
"Count(T_PRApprovalHistory.Workflow_Step_Date) AS CountOfWorkflow_Step_Date " & _
-
"FROM T_PRApprovalHistory " & _
-
"INNER JOIN tblWorkflowApprovalStep ON " & _
-
"T_PRApprovalHistory.Workflow_Step_Name = tblWorkflowApprovalStep.Workflow_Step_Name " & _
-
"GROUP BY T_PRApprovalHistory.PR_ID, " & _
-
"T_PRApprovalHistory.PR_Date, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Name, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date " & _
-
"HAVING T_PRApprovalHistory.PR_Date " & _
-
"Between #" & [Forms]![F_PR_Status]![txb_Start_Date] & _
-
"# And #" & [Forms]![F_PR_Status]![txb_End_Date] & "# " & _
-
"ORDER BY T_PRApprovalHistory.PR_ID, " & _
-
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
-
"T_PRApprovalHistory.Workflow_Step_Date;"
-
-
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
We were bound to get it sooner or later! (LOL)
NeoPa 32,556
Expert Mod 16PB
Nice work boys.
Sorry to hear you were in the ER Dowling. I hope all is sorted now and you're back to full health.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul |
last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and
session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
|
by: Mike Wimpe |
last post by:
Without creating a form, how do i pass a value to another script?
I would like to pass:
group = "Oranges"
to another script or at least just 'group' and initialize it in the
first script.
...
|
by: Resant |
last post by:
I have a query :
Exec 'Select * From Receiving Where Code In (' + @pCode + ')'
@pCode will contain more than one string parameter, eg : A1, A2, A3
How can i write that parameters, I try use :...
|
by: Michael DeLawter |
last post by:
Using Access 2002.
I have a chart in a report that is currently based on a query in which
the user enters the start and end date for the chart to display. Both
the start and end dates have been...
|
by: MX1 |
last post by:
HELP!
I have a query that gets a few values from a form. The problem I'm having
is a date field in the query. When I put the value in the criteria, it
works fine. When I put the same value as...
|
by: MX1 |
last post by:
I'm ready to pull the hair out of my head. I have a query with a couple of
parameters that I want to get from combo boxes on a form. One parameter is
a date with a dynamically calculated year and...
|
by: Greg Iocco |
last post by:
Simple problem, but I've checked the newsgroups and couldn't find an
answer.
On the main swithboard is a command button to open a report. The
report I built is based off a query, and the query...
|
by: Oleg Konovalov |
last post by:
Hi,
I am trying to pass a bunch of checked checkboxes (Javascript array)
from page1 to the Java action class on subsequent web page (page2).
(on page 1 I have a bunch of DB rows with a checkbox,...
|
by: jej1216 |
last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect...
|
by: robtyketto |
last post by:
Greetings,
I have a form where a combo box is used to select a name and Id.
Theses values are passed into a subform.
However the query now returns 0 results.
So I edited the query and hard...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |