slow response time in Access 2002 using a date variable for criter

G

Guest

I have converted an Access 97 database to Access 2002, (file format 2000). I
have a make table query that retrieves data from on Oracle database. I am
using a start and end date entered by the user in one of the criteria fields.
The response time in Access 2002 is about 20 mintes. In Access 97 it was
less than 1 minute. If I "hard code" the dates i.e. (between "07/09/2005#
and "07/15/2005#) in the query in the Access 2002 version, the response time
is less than one minute.

Any ideas what could be causing this slow response time using the variable
name ?

Thanks,
Barb
 
M

MGFoster

Barb said:
I have converted an Access 97 database to Access 2002, (file format 2000). I
have a make table query that retrieves data from on Oracle database. I am
using a start and end date entered by the user in one of the criteria fields.
The response time in Access 2002 is about 20 mintes. In Access 97 it was
less than 1 minute. If I "hard code" the dates i.e. (between "07/09/2005#
and "07/15/2005#) in the query in the Access 2002 version, the response time
is less than one minute.

Any ideas what could be causing this slow response time using the variable
name ?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The correct syntax for "hard coding" a date is #07/09/2005#.

You don't say how you're getting the date from the user - is it a query
pop-up prompt, or a form reference?

You could explicitly specify the parameter data type by putting
something like this in the query:

PARAMETERS [Start Date?] Date, [End Date?] Date;
SELECT ... etc.

The above is an example of a pop-up parameter. Here is an example of
using a form reference parameter:

PARAMETERS Forms!CriteriaForm!txtFrom Date,
Forms!CriteriaForm!txtTo Date;
SELECT ... etc.

When you explicitly declare the data type of the parameters, Access
doesn't have to "guess" the data type and try to convert it to the
proper data type. This should speed up the query a little.

You also don't say if the query is a JET (Access) query or an SQL Pass
Through (SPT) query. Usually, using an SPT will result in a quicker
query 'cuz it is letting the RDBMS server (Oracle, in your case) do the
processing. The SPT has to use the RDBMS's SQL syntax, not JET's SQL
syntax. Read the Access SQL articles on pass thru queries for more
info.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQuB29YechKqOuFEgEQLP0QCgqzkcaYwHUjBxwO9GeQq4oCQJ3VMAoIWV
l252f1qMnoeikIrI3yB+xiWJ
=mr4Z
-----END PGP SIGNATURE-----
 
G

Guest

MGFoster said:
Barb said:
I have converted an Access 97 database to Access 2002, (file format 2000). I
have a make table query that retrieves data from on Oracle database. I am
using a start and end date entered by the user in one of the criteria fields.
The response time in Access 2002 is about 20 mintes. In Access 97 it was
less than 1 minute. If I "hard code" the dates i.e. (between "07/09/2005#
and "07/15/2005#) in the query in the Access 2002 version, the response time
is less than one minute.

Any ideas what could be causing this slow response time using the variable
name ?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The correct syntax for "hard coding" a date is #07/09/2005#.

You don't say how you're getting the date from the user - is it a query
pop-up prompt, or a form reference?

You could explicitly specify the parameter data type by putting
something like this in the query:

PARAMETERS [Start Date?] Date, [End Date?] Date;
SELECT ... etc.

The above is an example of a pop-up parameter. Here is an example of
using a form reference parameter:

PARAMETERS Forms!CriteriaForm!txtFrom Date,
Forms!CriteriaForm!txtTo Date;
SELECT ... etc.

When you explicitly declare the data type of the parameters, Access
doesn't have to "guess" the data type and try to convert it to the
proper data type. This should speed up the query a little.

You also don't say if the query is a JET (Access) query or an SQL Pass
Through (SPT) query. Usually, using an SPT will result in a quicker
query 'cuz it is letting the RDBMS server (Oracle, in your case) do the
processing. The SPT has to use the RDBMS's SQL syntax, not JET's SQL
syntax. Read the Access SQL articles on pass thru queries for more
info.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQuB29YechKqOuFEgEQLP0QCgqzkcaYwHUjBxwO9GeQq4oCQJ3VMAoIWV
l252f1qMnoeikIrI3yB+xiWJ
=mr4Z
-----END PGP SIGNATURE-----


Yes, sorry about the typo on my part. I did have the correct syntax for the
hard coded date.

I am getting the date from the user via a VBA module:

Option Compare Database
Public getd As Integer
Public DayNum As Long 'Number of days since first of year
Public WeekNum As Long 'Number of Weeks since first of year
Public MonthNum As Long 'Number of Weeks since first of year

Public begin As Date
Public finish As Date

Option Explicit
Public Static Function Startdate(getp As Integer)
Static start As Date
Static DateSTR As String
Static MonthSTR As String
Static YearSTR As String

' Getd 0 will reset the start and end date to yesterday
' Getd 1 will get the start or end date
' Getd 2 will change the start or end date
' Getd 3 will show the start or end date

' The following are automated dates.
' Getd 7 will set the start and end date to the previous week
' Getd 8 will set the start and end date to this Week up to and including
today.
' Getd 11 will set the start and end date to the previous Month
' Getd 12 will set the start and end date to this Month to date

getd = getp

If getp = 2 Then
start = InputBox("Enter start date ")
Startdate = start
Else
If getp = 0 Then
' set to yesterday's date
start = Format(Now() - 1, "mm-dd-yy")
Startdate = start
ElseIf getp = 7 Then
' Set to Last weeks starting date (Saturday)
start = Format(Now() - (WeekDay(Now(), vbSaturday) + 6), "mm-dd-yy")
Startdate = start
ElseIf getp = 8 Then
' Set to Beginning of this week starting date
start = Format(Now() - (WeekDay(Now(), vbSaturday) - 1), "mm-dd-yy")
Startdate = start
ElseIf getp = 11 Then
' Set to Last Months start date
YearSTR = Year(Now())
MonthSTR = Month(Now()) - 1
If MonthSTR = 0 Then
MonthSTR = 12 ' beginning of year rap back
YearSTR = YearSTR - 1 ' wrap back to previous year
End If
DateSTR = MonthSTR + "-01-" + YearSTR
start = Format(DateSTR, "mm-dd-yy")
Startdate = start
ElseIf getp = 12 Then
' Set to beginning of this Months start date
MonthSTR = Month(Now())
YearSTR = Year(Now())
DateSTR = MonthSTR + "-01-" + YearSTR
start = Format(DateSTR, "mm-dd-yy")
Startdate = start
Else
Startdate = start
End If


Debug.Print Startdate
Debug.Print getp 'Debug info
Debug.Print start
End If
begin = start
Debug.Print begin
End Function

Public Static Function Enddate(getd)
Static endd As Date

If getd = 2 Then
endd = InputBox("Enter Ending date ")
Enddate = endd
Else
If getd = 3 Then
' Display the current end date
Enddate = endd
Else
If (getd = 0 Or getd = 8 Or getd = 12) Then
endd = Format(Now(), "mm-dd-yy")
Enddate = endd
ElseIf getd = 7 Then
endd = Format(Now() - (WeekDay(Now(), vbSaturday)), "mm-dd-yy")
Enddate = endd
ElseIf getd = 11 Then
endd = Format(Now() - (Day(Now())), "mm-dd-yy")
Enddate = endd
Else
Enddate = endd
End If
End If
End If
Debug.Print Enddate
Debug.Print getd
Debug.Print endd

finish = endd

Debug.Print finish

End Function

The start and end dates are initialzed to a certain date, such as,
=Startdate(3), on the main input form field, or the user can change the start
and end dates.
The variable in the make table JET query uses "Between Startdate(1) and
Enddate(1)"
as the criteria for the date field. In debug mode, when I run ?
Startdate(1), the date format returned is 7/9/2005.

I have inherited this program from someone no longer here, and don't know as
much about Access as he did, but I am learning more and more as I go.

When I run the query with the date variable (before I turn it into a make
table query) the response time is quick. The long repsonse time comes in
when I turn it into a make table query and run it.

I also tried a pass through query, but wasn't sure how to reference the date
variable field in that query. It did not like recognixe Startdate(1).

Thanks very much for your help,
Barb
 
M

MGFoster

Barb said:
:

Barb said:
I have converted an Access 97 database to Access 2002, (file format 2000). I
have a make table query that retrieves data from on Oracle database. I am
using a start and end date entered by the user in one of the criteria fields.
The response time in Access 2002 is about 20 mintes. In Access 97 it was
less than 1 minute. If I "hard code" the dates i.e. (between "07/09/2005#
and "07/15/2005#) in the query in the Access 2002 version, the response time
is less than one minute.

Any ideas what could be causing this slow response time using the variable
name ?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The correct syntax for "hard coding" a date is #07/09/2005#.

You don't say how you're getting the date from the user - is it a query
pop-up prompt, or a form reference?

You could explicitly specify the parameter data type by putting
something like this in the query:

PARAMETERS [Start Date?] Date, [End Date?] Date;
SELECT ... etc.

The above is an example of a pop-up parameter. Here is an example of
using a form reference parameter:

PARAMETERS Forms!CriteriaForm!txtFrom Date,
Forms!CriteriaForm!txtTo Date;
SELECT ... etc.

When you explicitly declare the data type of the parameters, Access
doesn't have to "guess" the data type and try to convert it to the
proper data type. This should speed up the query a little.

You also don't say if the query is a JET (Access) query or an SQL Pass
Through (SPT) query. Usually, using an SPT will result in a quicker
query 'cuz it is letting the RDBMS server (Oracle, in your case) do the
processing. The SPT has to use the RDBMS's SQL syntax, not JET's SQL
syntax. Read the Access SQL articles on pass thru queries for more
info.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQuB29YechKqOuFEgEQLP0QCgqzkcaYwHUjBxwO9GeQq4oCQJ3VMAoIWV
l252f1qMnoeikIrI3yB+xiWJ
=mr4Z
-----END PGP SIGNATURE-----



Yes, sorry about the typo on my part. I did have the correct syntax for the
hard coded date.

I am getting the date from the user via a VBA module:

Option Compare Database
Public getd As Integer
Public DayNum As Long 'Number of days since first of year
Public WeekNum As Long 'Number of Weeks since first of year
Public MonthNum As Long 'Number of Weeks since first of year

Public begin As Date
Public finish As Date

Option Explicit
Public Static Function Startdate(getp As Integer)
Static start As Date
Static DateSTR As String
Static MonthSTR As String
Static YearSTR As String

' Getd 0 will reset the start and end date to yesterday
' Getd 1 will get the start or end date
' Getd 2 will change the start or end date
' Getd 3 will show the start or end date

' The following are automated dates.
' Getd 7 will set the start and end date to the previous week
' Getd 8 will set the start and end date to this Week up to and including
today.
' Getd 11 will set the start and end date to the previous Month
' Getd 12 will set the start and end date to this Month to date

getd = getp

If getp = 2 Then
start = InputBox("Enter start date ")
Startdate = start
Else
If getp = 0 Then
' set to yesterday's date
start = Format(Now() - 1, "mm-dd-yy")
Startdate = start
ElseIf getp = 7 Then
' Set to Last weeks starting date (Saturday)
start = Format(Now() - (WeekDay(Now(), vbSaturday) + 6), "mm-dd-yy")
Startdate = start
ElseIf getp = 8 Then
' Set to Beginning of this week starting date
start = Format(Now() - (WeekDay(Now(), vbSaturday) - 1), "mm-dd-yy")
Startdate = start
ElseIf getp = 11 Then
' Set to Last Months start date
YearSTR = Year(Now())
MonthSTR = Month(Now()) - 1
If MonthSTR = 0 Then
MonthSTR = 12 ' beginning of year rap back
YearSTR = YearSTR - 1 ' wrap back to previous year
End If
DateSTR = MonthSTR + "-01-" + YearSTR
start = Format(DateSTR, "mm-dd-yy")
Startdate = start
ElseIf getp = 12 Then
' Set to beginning of this Months start date
MonthSTR = Month(Now())
YearSTR = Year(Now())
DateSTR = MonthSTR + "-01-" + YearSTR
start = Format(DateSTR, "mm-dd-yy")
Startdate = start
Else
Startdate = start
End If


Debug.Print Startdate
Debug.Print getp 'Debug info
Debug.Print start
End If
begin = start
Debug.Print begin
End Function

Public Static Function Enddate(getd)
Static endd As Date

If getd = 2 Then
endd = InputBox("Enter Ending date ")
Enddate = endd
Else
If getd = 3 Then
' Display the current end date
Enddate = endd
Else
If (getd = 0 Or getd = 8 Or getd = 12) Then
endd = Format(Now(), "mm-dd-yy")
Enddate = endd
ElseIf getd = 7 Then
endd = Format(Now() - (WeekDay(Now(), vbSaturday)), "mm-dd-yy")
Enddate = endd
ElseIf getd = 11 Then
endd = Format(Now() - (Day(Now())), "mm-dd-yy")
Enddate = endd
Else
Enddate = endd
End If
End If
End If
Debug.Print Enddate
Debug.Print getd
Debug.Print endd

finish = endd

Debug.Print finish

End Function

The start and end dates are initialzed to a certain date, such as,
=Startdate(3), on the main input form field, or the user can change the start
and end dates.
The variable in the make table JET query uses "Between Startdate(1) and
Enddate(1)"
as the criteria for the date field. In debug mode, when I run ?
Startdate(1), the date format returned is 7/9/2005.

I have inherited this program from someone no longer here, and don't know as
much about Access as he did, but I am learning more and more as I go.

When I run the query with the date variable (before I turn it into a make
table query) the response time is quick. The long repsonse time comes in
when I turn it into a make table query and run it.

I also tried a pass through query, but wasn't sure how to reference the date
variable field in that query. It did not like recognixe Startdate(1).

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Well, this code does a lot of tap dancing just to do some simple date
calculations. The functions return string variants when they should be
returning Date data types. It would be easier to do the date
calculation in the query or in a form that runs the query instead of
calling these functions. A function that is called by a query should
NEVER have a user prompt (the InputBox), IMNSHO.

What I'd do: Set up a form that accepts the user's criteria & runs the
query. Use form references in the query to get the criteria from the
form.

Form reference in a query:

PARAMETERS Forms!frmCriteria!txtFromDate Date,
Forms!frmCriteria!txtToDate Date;
SELECT ...
FROM ...
WHERE date_column Between Forms!frmCriteria!txtFromDate And
Forms!frmCriteria!txtToDate

How to calculate dates: Use the date functions:

Yesterday: DateAdd("d", -1, Date())
Beginning of current month: Date() - Day(Date()) + 1
End of current month: DateAdd("m", 1, Date() - Day(Date()) + 1) -1

Search Google Groups in comp.databases.ms-access for date calculations,
there are many discussions that will show you how to use the Date
functions to calculate different dates.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQuE6w4echKqOuFEgEQKGlQCfZxF5MIJATg+DJVw0hKze1RvQiFEAoNXi
sDKSpPg2d6EKegC/OoffvEAF
=mM4q
-----END PGP SIGNATURE-----
 
G

Guest

MGFoster said:
Barb said:
:

Barb wrote:

I have converted an Access 97 database to Access 2002, (file format 2000). I
have a make table query that retrieves data from on Oracle database. I am
using a start and end date entered by the user in one of the criteria fields.
The response time in Access 2002 is about 20 mintes. In Access 97 it was
less than 1 minute. If I "hard code" the dates i.e. (between "07/09/2005#
and "07/15/2005#) in the query in the Access 2002 version, the response time
is less than one minute.

Any ideas what could be causing this slow response time using the variable
name ?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The correct syntax for "hard coding" a date is #07/09/2005#.

You don't say how you're getting the date from the user - is it a query
pop-up prompt, or a form reference?

You could explicitly specify the parameter data type by putting
something like this in the query:

PARAMETERS [Start Date?] Date, [End Date?] Date;
SELECT ... etc.

The above is an example of a pop-up parameter. Here is an example of
using a form reference parameter:

PARAMETERS Forms!CriteriaForm!txtFrom Date,
Forms!CriteriaForm!txtTo Date;
SELECT ... etc.

When you explicitly declare the data type of the parameters, Access
doesn't have to "guess" the data type and try to convert it to the
proper data type. This should speed up the query a little.

You also don't say if the query is a JET (Access) query or an SQL Pass
Through (SPT) query. Usually, using an SPT will result in a quicker
query 'cuz it is letting the RDBMS server (Oracle, in your case) do the
processing. The SPT has to use the RDBMS's SQL syntax, not JET's SQL
syntax. Read the Access SQL articles on pass thru queries for more
info.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQuB29YechKqOuFEgEQLP0QCgqzkcaYwHUjBxwO9GeQq4oCQJ3VMAoIWV
l252f1qMnoeikIrI3yB+xiWJ
=mr4Z
-----END PGP SIGNATURE-----



Yes, sorry about the typo on my part. I did have the correct syntax for the
hard coded date.

I am getting the date from the user via a VBA module:

Option Compare Database
Public getd As Integer
Public DayNum As Long 'Number of days since first of year
Public WeekNum As Long 'Number of Weeks since first of year
Public MonthNum As Long 'Number of Weeks since first of year

Public begin As Date
Public finish As Date

Option Explicit
Public Static Function Startdate(getp As Integer)
Static start As Date
Static DateSTR As String
Static MonthSTR As String
Static YearSTR As String

' Getd 0 will reset the start and end date to yesterday
' Getd 1 will get the start or end date
' Getd 2 will change the start or end date
' Getd 3 will show the start or end date

' The following are automated dates.
' Getd 7 will set the start and end date to the previous week
' Getd 8 will set the start and end date to this Week up to and including
today.
' Getd 11 will set the start and end date to the previous Month
' Getd 12 will set the start and end date to this Month to date

getd = getp

If getp = 2 Then
start = InputBox("Enter start date ")
Startdate = start
Else
If getp = 0 Then
' set to yesterday's date
start = Format(Now() - 1, "mm-dd-yy")
Startdate = start
ElseIf getp = 7 Then
' Set to Last weeks starting date (Saturday)
start = Format(Now() - (WeekDay(Now(), vbSaturday) + 6), "mm-dd-yy")
Startdate = start
ElseIf getp = 8 Then
' Set to Beginning of this week starting date
start = Format(Now() - (WeekDay(Now(), vbSaturday) - 1), "mm-dd-yy")
Startdate = start
ElseIf getp = 11 Then
' Set to Last Months start date
YearSTR = Year(Now())
MonthSTR = Month(Now()) - 1
If MonthSTR = 0 Then
MonthSTR = 12 ' beginning of year rap back
YearSTR = YearSTR - 1 ' wrap back to previous year
End If
DateSTR = MonthSTR + "-01-" + YearSTR
start = Format(DateSTR, "mm-dd-yy")
Startdate = start
ElseIf getp = 12 Then
' Set to beginning of this Months start date
MonthSTR = Month(Now())
YearSTR = Year(Now())
DateSTR = MonthSTR + "-01-" + YearSTR
start = Format(DateSTR, "mm-dd-yy")
Startdate = start
Else
Startdate = start
End If


Debug.Print Startdate
Debug.Print getp 'Debug info
Debug.Print start
End If
begin = start
Debug.Print begin
End Function

Public Static Function Enddate(getd)
Static endd As Date

If getd = 2 Then
endd = InputBox("Enter Ending date ")
Enddate = endd
Else
If getd = 3 Then
' Display the current end date
Enddate = endd
Else
If (getd = 0 Or getd = 8 Or getd = 12) Then
endd = Format(Now(), "mm-dd-yy")
Enddate = endd
ElseIf getd = 7 Then
endd = Format(Now() - (WeekDay(Now(), vbSaturday)), "mm-dd-yy")
Enddate = endd
ElseIf getd = 11 Then
endd = Format(Now() - (Day(Now())), "mm-dd-yy")
Enddate = endd
Else
Enddate = endd
End If
End If
End If
Debug.Print Enddate
Debug.Print getd
Debug.Print endd

finish = endd

Debug.Print finish

End Function

The start and end dates are initialzed to a certain date, such as,
=Startdate(3), on the main input form field, or the user can change the start
and end dates.
The variable in the make table JET query uses "Between Startdate(1) and
Enddate(1)"
as the criteria for the date field. In debug mode, when I run ?
Startdate(1), the date format returned is 7/9/2005.

I have inherited this program from someone no longer here, and don't know as
much about Access as he did, but I am learning more and more as I go.

When I run the query with the date variable (before I turn it into a make
table query) the response time is quick. The long repsonse time comes in
when I turn it into a make table query and run it.

I also tried a pass through query, but wasn't sure how to reference the date
variable field in that query. It did not like recognixe Startdate(1).

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Well, this code does a lot of tap dancing just to do some simple date
calculations. The functions return string variants when they should be
returning Date data types. It would be easier to do the date
calculation in the query or in a form that runs the query instead of
calling these functions. A function that is called by a query should
NEVER have a user prompt (the InputBox), IMNSHO.

What I'd do: Set up a form that accepts the user's criteria & runs the
query. Use form references in the query to get the criteria from the
form.

Form reference in a query:

PARAMETERS Forms!frmCriteria!txtFromDate Date,
Forms!frmCriteria!txtToDate Date;
SELECT ...
FROM ...
WHERE date_column Between Forms!frmCriteria!txtFromDate And
Forms!frmCriteria!txtToDate

How to calculate dates: Use the date functions:

Yesterday: DateAdd("d", -1, Date())
Beginning of current month: Date() - Day(Date()) + 1
End of current month: DateAdd("m", 1, Date() - Day(Date()) + 1) -1

Search Google Groups in comp.databases.ms-access for date calculations,
there are many discussions that will show you how to use the Date
functions to calculate different dates.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQuE6w4echKqOuFEgEQKGlQCfZxF5MIJATg+DJVw0hKze1RvQiFEAoNXi
sDKSpPg2d6EKegC/OoffvEAF
=mM4q
-----END PGP SIGNATURE-----


Thanks for the suggestions. I was hoping to not have to change the existing
code on how the dates were gathered. There are serveral other modules that
would have to be changed also, which are beyond my skill level at this point.
I was mostly wondering why this origianl code worked so quickly in Access
97, but so slowly in Access 2002.

Barb
 
G

Guest

MGFoster said:
Barb said:
:

Barb wrote:

I have converted an Access 97 database to Access 2002, (file format 2000). I
have a make table query that retrieves data from on Oracle database. I am
using a start and end date entered by the user in one of the criteria fields.
The response time in Access 2002 is about 20 mintes. In Access 97 it was
less than 1 minute. If I "hard code" the dates i.e. (between "07/09/2005#
and "07/15/2005#) in the query in the Access 2002 version, the response time
is less than one minute.

Any ideas what could be causing this slow response time using the variable
name ?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The correct syntax for "hard coding" a date is #07/09/2005#.

You don't say how you're getting the date from the user - is it a query
pop-up prompt, or a form reference?

You could explicitly specify the parameter data type by putting
something like this in the query:

PARAMETERS [Start Date?] Date, [End Date?] Date;
SELECT ... etc.

The above is an example of a pop-up parameter. Here is an example of
using a form reference parameter:

PARAMETERS Forms!CriteriaForm!txtFrom Date,
Forms!CriteriaForm!txtTo Date;
SELECT ... etc.

When you explicitly declare the data type of the parameters, Access
doesn't have to "guess" the data type and try to convert it to the
proper data type. This should speed up the query a little.

You also don't say if the query is a JET (Access) query or an SQL Pass
Through (SPT) query. Usually, using an SPT will result in a quicker
query 'cuz it is letting the RDBMS server (Oracle, in your case) do the
processing. The SPT has to use the RDBMS's SQL syntax, not JET's SQL
syntax. Read the Access SQL articles on pass thru queries for more
info.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQuB29YechKqOuFEgEQLP0QCgqzkcaYwHUjBxwO9GeQq4oCQJ3VMAoIWV
l252f1qMnoeikIrI3yB+xiWJ
=mr4Z
-----END PGP SIGNATURE-----



Yes, sorry about the typo on my part. I did have the correct syntax for the
hard coded date.

I am getting the date from the user via a VBA module:

Option Compare Database
Public getd As Integer
Public DayNum As Long 'Number of days since first of year
Public WeekNum As Long 'Number of Weeks since first of year
Public MonthNum As Long 'Number of Weeks since first of year

Public begin As Date
Public finish As Date

Option Explicit
Public Static Function Startdate(getp As Integer)
Static start As Date
Static DateSTR As String
Static MonthSTR As String
Static YearSTR As String

' Getd 0 will reset the start and end date to yesterday
' Getd 1 will get the start or end date
' Getd 2 will change the start or end date
' Getd 3 will show the start or end date

' The following are automated dates.
' Getd 7 will set the start and end date to the previous week
' Getd 8 will set the start and end date to this Week up to and including
today.
' Getd 11 will set the start and end date to the previous Month
' Getd 12 will set the start and end date to this Month to date

getd = getp

If getp = 2 Then
start = InputBox("Enter start date ")
Startdate = start
Else
If getp = 0 Then
' set to yesterday's date
start = Format(Now() - 1, "mm-dd-yy")
Startdate = start
ElseIf getp = 7 Then
' Set to Last weeks starting date (Saturday)
start = Format(Now() - (WeekDay(Now(), vbSaturday) + 6), "mm-dd-yy")
Startdate = start
ElseIf getp = 8 Then
' Set to Beginning of this week starting date
start = Format(Now() - (WeekDay(Now(), vbSaturday) - 1), "mm-dd-yy")
Startdate = start
ElseIf getp = 11 Then
' Set to Last Months start date
YearSTR = Year(Now())
MonthSTR = Month(Now()) - 1
If MonthSTR = 0 Then
MonthSTR = 12 ' beginning of year rap back
YearSTR = YearSTR - 1 ' wrap back to previous year
End If
DateSTR = MonthSTR + "-01-" + YearSTR
start = Format(DateSTR, "mm-dd-yy")
Startdate = start
ElseIf getp = 12 Then
' Set to beginning of this Months start date
MonthSTR = Month(Now())
YearSTR = Year(Now())
DateSTR = MonthSTR + "-01-" + YearSTR
start = Format(DateSTR, "mm-dd-yy")
Startdate = start
Else
Startdate = start
End If


Debug.Print Startdate
Debug.Print getp 'Debug info
Debug.Print start
End If
begin = start
Debug.Print begin
End Function

Public Static Function Enddate(getd)
Static endd As Date

If getd = 2 Then
endd = InputBox("Enter Ending date ")
Enddate = endd
Else
If getd = 3 Then
' Display the current end date
Enddate = endd
Else
If (getd = 0 Or getd = 8 Or getd = 12) Then
endd = Format(Now(), "mm-dd-yy")
Enddate = endd
ElseIf getd = 7 Then
endd = Format(Now() - (WeekDay(Now(), vbSaturday)), "mm-dd-yy")
Enddate = endd
ElseIf getd = 11 Then
endd = Format(Now() - (Day(Now())), "mm-dd-yy")
Enddate = endd
Else
Enddate = endd
End If
End If
End If
Debug.Print Enddate
Debug.Print getd
Debug.Print endd

finish = endd

Debug.Print finish

End Function

The start and end dates are initialzed to a certain date, such as,
=Startdate(3), on the main input form field, or the user can change the start
and end dates.
The variable in the make table JET query uses "Between Startdate(1) and
Enddate(1)"
as the criteria for the date field. In debug mode, when I run ?
Startdate(1), the date format returned is 7/9/2005.

I have inherited this program from someone no longer here, and don't know as
much about Access as he did, but I am learning more and more as I go.

When I run the query with the date variable (before I turn it into a make
table query) the response time is quick. The long repsonse time comes in
when I turn it into a make table query and run it.

I also tried a pass through query, but wasn't sure how to reference the date
variable field in that query. It did not like recognixe Startdate(1).

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Well, this code does a lot of tap dancing just to do some simple date
calculations. The functions return string variants when they should be
returning Date data types. It would be easier to do the date
calculation in the query or in a form that runs the query instead of
calling these functions. A function that is called by a query should
NEVER have a user prompt (the InputBox), IMNSHO.

What I'd do: Set up a form that accepts the user's criteria & runs the
query. Use form references in the query to get the criteria from the
form.

Form reference in a query:

PARAMETERS Forms!frmCriteria!txtFromDate Date,
Forms!frmCriteria!txtToDate Date;
SELECT ...
FROM ...
WHERE date_column Between Forms!frmCriteria!txtFromDate And
Forms!frmCriteria!txtToDate

How to calculate dates: Use the date functions:

Yesterday: DateAdd("d", -1, Date())
Beginning of current month: Date() - Day(Date()) + 1
End of current month: DateAdd("m", 1, Date() - Day(Date()) + 1) -1

Search Google Groups in comp.databases.ms-access for date calculations,
there are many discussions that will show you how to use the Date
functions to calculate different dates.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQuE6w4echKqOuFEgEQKGlQCfZxF5MIJATg+DJVw0hKze1RvQiFEAoNXi
sDKSpPg2d6EKegC/OoffvEAF
=mM4q
-----END PGP SIGNATURE-----
MGFoster,

I tried something that I thought I could try fairly easily without changing
a lot of code, which was adding AS Date to the end of the function
definition lines:

Public Static Function Startdate(getp As Integer) As Date

as well as to the line

Public Static Function Enddate(getd) As Date

and I believe that it corrected the problem!!

Thanks again for your input.
I know this does not tell me why it worked in Access 97 but not in Access
2002, but at this point, I'm not really sure I care. :)

Barb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top