|
 |
access thread: one fuction on more forms
Message #1 by "Nikola" <Nikola@b...> on Fri, 22 Nov 2002 00:47:35 -0000
|
|
hi , all
How i can use one function :
Function SQLData(varDate As Variant) As String
If isData(varDate) Then
SQLDate = "#" & Format&(vadDate, "mm\/dd\/yyyy") & "#"
End If
End Function
on more forms ?
Thanks
Message #2 by "Bob Bedell" <bobbedell15@m...> on Fri, 22 Nov 2002 04:41:29 +0000
|
|
Hi Nikola,
Add a new module to your application and paste your function into it.
Your function is public by default, and can be called from any form
in your application as follows:
Private Sub txtDate_AfterUpdate()
Dim strDate As String
Dim strSQL As String
' Force date into American format for JET SQL clause.
If Not IsNull([txtDate]) Then
strDate = SQLDate([txtDate])
End If
strSQL = "SELECT * FROM tblOrders " & _
"WHERE OrderDate > " & strDate
End Sub
The AfterUpdate event is arbitrary. Use any procedure you like to
build your SQL string.
Best,
Bob
>From: "Nikola" <Nikola@b...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] one fuction on more forms
>Date: Fri, 22 Nov 2002 00:47:35 -0000
>
>hi , all
>
>How i can use one function :
>
>Function SQLData(varDate As Variant) As String
>If isData(varDate) Then
>SQLDate = "#" & Format&(vadDate, "mm\/dd\/yyyy") & "#"
>End If
>End Function
>
>on more forms ?
>
>Thanks
>
>
_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
Message #3 by "Nikola" <Nikola@b...> on Fri, 22 Nov 2002 09:01:15 -0000
|
|
Hi Bob, Thanks and I have one more Question :
Let say I have form with txtStartDate,TxtEndDate and button Preview.Is
correct like this :
text Box Control :
Name : txtStartDate
Format : dd/mmm/yyyy
Input Mask : 99/99/0000;0;_
Same for txtEndDate, now on Preview button on Click event i have code :
Private Sub Preview_Click()
On Error GoTo Err_Preview_Click
Dim strDocName As String
Dim strWhere As String
Dim strField As String
Const USAdate = "\#mm\/dd\/yyyy\#"
strDocName = "rpt_test"
strField = "TransactionDate"
If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
MsgBox "Test"
Me.txtStartDate.SetFocus
Else
strWhere = strField & " Between " & Format(Me.txtStartDate, USAdate) _
& " And " & Format(Me.txtEndDate, USAdate)
End If
'Debug.Print strWhere
DoCmd.OpenReport strDocName, acPreview, , strWhere
Exit_Preview_Click:
Exit Sub
Err_Preview_Click:
MsgBox Err.Description
Resume Exit_Preview_Click
End Sub
I didn't create SQL try VBA because I'm not still sure how to make
completely :-( , any way in code above strField = "TransactionDate" <- is
field from Query.I just want to now if is this correct way because i need to
send database to USA. so it will work normally if I make for all my date
field settings like above? Here on all PC Reg Settings are dd/mmm/yyyy
Thanks
-----Original Message-----
From: Bob Bedell [mailto:bobbedell15@m...]
Sent: Friday, November 22, 2002 4:41 AM
To: Access
Subject: [access] Re: one fuction on more forms
Hi Nikola,
Add a new module to your application and paste your function into it.
Your function is public by default, and can be called from any form
in your application as follows:
Private Sub txtDate_AfterUpdate()
Dim strDate As String
Dim strSQL As String
' Force date into American format for JET SQL clause.
If Not IsNull([txtDate]) Then
strDate = SQLDate([txtDate])
End If
strSQL = "SELECT * FROM tblOrders " & _
"WHERE OrderDate > " & strDate
End Sub
The AfterUpdate event is arbitrary. Use any procedure you like to
build your SQL string.
Best,
Bob
>From: "Nikola" <Nikola@b...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] one fuction on more forms
>Date: Fri, 22 Nov 2002 00:47:35 -0000
>
>hi , all
>
>How i can use one function :
>
>Function SQLData(varDate As Variant) As String
>If isData(varDate) Then
>SQLDate = "#" & Format&(vadDate, "mm\/dd\/yyyy") & "#"
>End If
>End Function
>
>on more forms ?
>
>Thanks
>
>
_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
Message #4 by "bwarehouse" <bwarehouse@y...> on Fri, 22 Nov 2002 04:08:17 -0700
|
|
Sounds like you saved that function at the procedure level and privatized it
(only that current form can use). Copy that code and create a new module
and paste that code and save the module with a meaningful name,,, goback
and delete the original function, now when you want to use (call)
That function, all you have to do is use the name of the function any within
the dbase.
Later,
b.ware
-----Original Message-----
From: Nikola [mailto:Nikola@b...]
Sent: Thursday, November 21, 2002 5:48 PM
To: Access
Subject: [access] one fuction on more forms
hi , all
How i can use one function :
Function SQLData(varDate As Variant) As String
If isData(varDate) Then
SQLDate = "#" & Format&(vadDate, "mm\/dd\/yyyy") & "#"
End If
End Function
on more forms ?
Thanks
Message #5 by "Gregory Serrano" <SerranoG@m...> on Fri, 22 Nov 2002 13:32:10
|
|
Nikola,
RE: your function, namely...
Function SQLData(varDate As Variant) As String
If isData(varDate) Then
SQLDate = "#" & Format&(vadDate, "mm\/dd\/yyyy") & "#"
End If
End Function
Bob answered your question about calling it from different forms, but
there's something else you should notice. A function must return a
value. The above function doesn't always do that. You need to return a
value for the function if isData(varDate) is false as well.
If isData(varDate) Then
SQLDate = "#" & Format&(vadDate, "mm\/dd\/yyyy") & "#"
Else
SQLDate = {something else}
End If
Greg
Message #6 by "Gregory Serrano" <SerranoG@m...> on Fri, 22 Nov 2002 13:36:10
|
|
Oh, and either the function must be renamed SQLDate (change the last "a"
to an "e") or the return values should be named SQLData (change the
last "e" to an "a"). Right now you have the function called SQLData, but
you're assigning SQLDate.
Greg
Message #7 by "Bob Bedell" <bobbedell15@m...> on Fri, 22 Nov 2002 17:45:43 +0000
|
|
<<I just want to now if is this correct way because i need to
send database to USA. so it will work normally if I make for all my date
field settings like above?>>
Hi Nikola,
Your code runs fine as written with the default regional settings over
here (M/d/yyyy). Your display format dd/mmm/yyyy may seem a little odd
at first to American users who are used to seeing 11/22/2002, but the
underlying regional settings here will give the JET engine the SQL date
format its looking for. Forcing the date format is, of course, an issue
only on your end. Hope that helps a bit.
Best,
Bob
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
Message #8 by "Bob Bedell" <bobbedell15@m...> on Fri, 22 Nov 2002 17:55:33 +0000
|
|
Just a second thought...
For further testing purposes, you can always temporarily change your
PC's regional settings and run your code under the new settings.
The default American short date format in Windows XP is M/d/yyyy,
and the default date separator is /
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
Message #9 by "Nikola" <Nikola@b...> on Fri, 22 Nov 2002 20:11:14 -0000
|
|
hi Bob,
Thanks again for replay.I will change display for American user in format
mm/dd/yyyy with input mask 99/99/0000;0;_ or you think is better m/d/yyyy
?and do you know how to do this ( copy from my previuse post) :
Let say I have form with txtStartDate,TxtEndDate and button Preview.
Is correct like this ?
text Box Control :
Name : txtStartDate
Format : dd/mmm/yyyy
Input Mask : 99/99/0000;0;_
Same for txtEndDate, now on Preview button on Click event i have code :
Private Sub Preview_Click()
On Error GoTo Err_Preview_Click
Dim strDocName As String
Dim strWhere As String
Dim strField As String
Const USAdate = "\#mm\/dd\/yyyy\#"
strDocName = "rpt_test"
strField = "TransactionDate"
If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
MsgBox "Test"
Me.txtStartDate.SetFocus
Else
strWhere = strField & " Between " & Format(Me.txtStartDate, USAdate) _
& " And " & Format(Me.txtEndDate, USAdate)
End If
'Debug.Print strWhere
DoCmd.OpenReport strDocName, acPreview, , strWhere
Exit_Preview_Click:
Exit Sub
Err_Preview_Click:
MsgBox Err.Description
Resume Exit_Preview_Click
End Sub
I'm still confused,
How to use function in query when query is not build from Code ?
Yes i was testing buy R settings mm/dd/yyyy or mm/dd/yy and is ok!!!
thanks one more time
-----Original Message-----
From: Bob Bedell [mailto:bobbedell15@m...]
Sent: Friday, November 22, 2002 5:46 PM
To: Access
Subject: [access] Re: one fuction on more forms
<<I just want to now if is this correct way because i need to
send database to USA. so it will work normally if I make for all my date
field settings like above?>>
Hi Nikola,
Your code runs fine as written with the default regional settings over
here (M/d/yyyy). Your display format dd/mmm/yyyy may seem a little odd
at first to American users who are used to seeing 11/22/2002, but the
underlying regional settings here will give the JET engine the SQL date
format its looking for. Forcing the date format is, of course, an issue
only on your end. Hope that helps a bit.
Best,
Bob
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
Message #10 by "Nikola" <Nikola@b...> on Fri, 22 Nov 2002 20:24:14 -0000
|
|
or to formulate my question:
in unbound form i have to field (txtStartDate and txtEndDate)and print
button.in button is this
code:
Private Sub Preview_Click()
On Error GoTo Err_Preview_Click
Dim strDocName As String
Dim strWhere As String
Dim strField As String
Const USAdate = "\#mm\/dd\/yyyy\#"
strDocName = "rpt_test"
strField = "TransactionDate"
If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
MsgBox "Test"
Me.txtStartDate.SetFocus
Else
strWhere = strField & " Between " & Format(Me.txtStartDate, USAdate) _
& " And " & Format(Me.txtEndDate, USAdate)
End If
'Debug.Print strWhere
DoCmd.OpenReport strDocName, acPreview, , strWhere
Exit_Preview_Click:
Exit Sub
Err_Preview_Click:
MsgBox Err.Description
Resume Exit_Preview_Click
End Sub
Now I make Query (qryTest)from Table Transaction and in criteria for field
"TransactionDate"
i put between [forms]![frmTest].[txtStartDate] AND
[forms]![frmTest].[txtEndDate]
And Source for Report is qryTest. Do i doing right or wrong?
Thanks
-----Original Message-----
From: Bob Bedell [mailto:bobbedell15@m...]
Sent: Friday, November 22, 2002 5:56 PM
To: Access
Subject: [access] Re: one fuction on more forms
Just a second thought...
For further testing purposes, you can always temporarily change your
PC's regional settings and run your code under the new settings.
The default American short date format in Windows XP is M/d/yyyy,
and the default date separator is /
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
Message #11 by "Bob Bedell" <bobbedell15@m...> on Fri, 22 Nov 2002 20:18:57 +0000
|
|
Hi Nikola,
These are really questions for your end user to decide. There isn't a
right or wrong answer. The only difference between the mm/dd/yyyy and
dd/mmm/yyyy display format is that some folks prefer one to the
other. I've seen both. Same with input masks. Some people will like
99/99/0000;0;_ and some people will think that typing the leading
zeros is a pain, and prefer no input mask at all. Its your call based
on what your users like.
Bob
>From: "Nikola" <Nikola@b...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Re: one fuction on more forms
>Date: Fri, 22 Nov 2002 20:11:14 -0000
>
>hi Bob,
>Thanks again for replay.I will change display for American user in format
>mm/dd/yyyy with input mask 99/99/0000;0;_ or you think is better m/d/yyyy
>?and do you know how to do this ( copy from my previuse post) :
>
>Let say I have form with txtStartDate,TxtEndDate and button Preview.
>Is correct like this ?
>
>text Box Control :
>Name : txtStartDate
>Format : dd/mmm/yyyy
>Input Mask : 99/99/0000;0;_
>
>Same for txtEndDate, now on Preview button on Click event i have code :
>Private Sub Preview_Click()
>On Error GoTo Err_Preview_Click
>
>Dim strDocName As String
>Dim strWhere As String
>Dim strField As String
>Const USAdate = "\#mm\/dd\/yyyy\#"
>
>strDocName = "rpt_test"
>strField = "TransactionDate"
>
>If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
> MsgBox "Test"
> Me.txtStartDate.SetFocus
>Else
> strWhere = strField & " Between " & Format(Me.txtStartDate, USAdate) _
> & " And " & Format(Me.txtEndDate, USAdate)
>
>End If
> 'Debug.Print strWhere
> DoCmd.OpenReport strDocName, acPreview, , strWhere
>
>Exit_Preview_Click:
> Exit Sub
>
>Err_Preview_Click:
> MsgBox Err.Description
> Resume Exit_Preview_Click
>
>End Sub
>
>I'm still confused,
>How to use function in query when query is not build from Code ?
>
>Yes i was testing buy R settings mm/dd/yyyy or mm/dd/yy and is ok!!!
>
>thanks one more time
>
>-----Original Message-----
>From: Bob Bedell [mailto:bobbedell15@m...]
>Sent: Friday, November 22, 2002 5:46 PM
>To: Access
>Subject: [access] Re: one fuction on more forms
>
>
><<I just want to now if is this correct way because i need to
>send database to USA. so it will work normally if I make for all my date
>field settings like above?>>
>
>Hi Nikola,
>
>Your code runs fine as written with the default regional settings over
>here (M/d/yyyy). Your display format dd/mmm/yyyy may seem a little odd
>at first to American users who are used to seeing 11/22/2002, but the
>underlying regional settings here will give the JET engine the SQL date
>format its looking for. Forcing the date format is, of course, an issue
>only on your end. Hope that helps a bit.
>
>Best,
>
>Bob
>
>
>
>_________________________________________________________________
>Add photos to your messages with MSN 8. Get 2 months FREE*.
>http://join.msn.com/?page=features/featuredemail
>
>
>
>
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
Message #12 by "Bob Bedell" <bobbedell15@m...> on Fri, 22 Nov 2002 20:56:50 +0000
|
|
Hi Nikola,
This is a good way to go. However, if you use a saved query you don't
need to set the WHERE clause in your code. I commented out the lines of code
you won't need below:
Private Sub cmdPreview_Click()
On Error GoTo Err_Preview_Click
Dim strDocName As String
Dim strWhere As String
Dim strField As String
Const USAdate = "\#mm\/dd\/yyyy\#"
strDocName = "rpt_test"
strField = "TransactionDate"
If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
MsgBox "Test"
Me.txtStartDate.SetFocus
Else
' strWhere = strField & " Between " & Format(Me.txtStartDate, USAdate) _
' & " And " & Format(Me.txtEndDate, USAdate)
Me.Visible = False
End If
' Debug.Print strWhere
' DoCmd.OpenReport strDocName, acPreview
Exit_Preview_Click:
Exit Sub
Err_Preview_Click:
MsgBox Err.Description
Resume Exit_Preview_Click
End Sub
I added the line Me.Visible = False. Heres why. Add the following code
to your report module:
Option Compare Database
Option Explicit
Private Sub Report_Close()
DoCmd.Close acForm, "frmTest"
End Sub
Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmTest", , , , , acDialog, "rpt_Test"
End Sub
Now open your report. You want to open frmTest from your reports
Open event to make sure frmTest is loaded and filled with dates. That
way, qryTest can "see" the parameters in frmTest that it needs to
set rpt_Test's record source. Make sense? Let me know how it works.
Best,
Bob
>From: "Nikola" <Nikola@b...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Re: one fuction on more forms
>Date: Fri, 22 Nov 2002 20:24:14 -0000
>
>or to formulate my question:
>
>in unbound form i have to field (txtStartDate and txtEndDate)and print
>button.in button is this
>code:
>Private Sub Preview_Click()
>On Error GoTo Err_Preview_Click
>
>Dim strDocName As String
>Dim strWhere As String
>Dim strField As String
>Const USAdate = "\#mm\/dd\/yyyy\#"
>
>strDocName = "rpt_test"
>strField = "TransactionDate"
>
>If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
> MsgBox "Test"
> Me.txtStartDate.SetFocus
>Else
> strWhere = strField & " Between " & Format(Me.txtStartDate, USAdate) _
> & " And " & Format(Me.txtEndDate, USAdate)
>
>End If
> 'Debug.Print strWhere
> DoCmd.OpenReport strDocName, acPreview, , strWhere
>
>Exit_Preview_Click:
> Exit Sub
>
>Err_Preview_Click:
> MsgBox Err.Description
> Resume Exit_Preview_Click
>
>End Sub
>
>Now I make Query (qryTest)from Table Transaction and in criteria for field
>"TransactionDate"
>i put between [forms]![frmTest].[txtStartDate] AND
>[forms]![frmTest].[txtEndDate]
>And Source for Report is qryTest. Do i doing right or wrong?
>
>Thanks
>
>-----Original Message-----
>From: Bob Bedell [mailto:bobbedell15@m...]
>Sent: Friday, November 22, 2002 5:56 PM
>To: Access
>Subject: [access] Re: one fuction on more forms
>
>
>Just a second thought...
>
>For further testing purposes, you can always temporarily change your
>PC's regional settings and run your code under the new settings.
>The default American short date format in Windows XP is M/d/yyyy,
>and the default date separator is /
>
>_________________________________________________________________
>Protect your PC - get McAfee.com VirusScan Online
>http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
>
>
>
>
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail
Message #13 by "Bob Bedell" <bobbedell15@m...> on Fri, 22 Nov 2002 21:23:43 +0000
|
|
Oops...I messed up :(
Disregard that last post. Forgot you need you formatting
function.
Bob
>From: "Bob Bedell" <bobbedell15@m...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Re: one fuction on more forms
>Date: Fri, 22 Nov 2002 20:56:50 +0000
>
>Hi Nikola,
>
>This is a good way to go. However, if you use a saved query you don't
>need to set the WHERE clause in your code. I commented out the lines of
>code you won't need below:
>
>Private Sub cmdPreview_Click()
>On Error GoTo Err_Preview_Click
>
>Dim strDocName As String
>Dim strWhere As String
>Dim strField As String
>Const USAdate = "\#mm\/dd\/yyyy\#"
>
>strDocName = "rpt_test"
>strField = "TransactionDate"
>
>If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
> MsgBox "Test"
> Me.txtStartDate.SetFocus
>Else
>' strWhere = strField & " Between " & Format(Me.txtStartDate, USAdate) _
>' & " And " & Format(Me.txtEndDate, USAdate)
>Me.Visible = False
>End If
>' Debug.Print strWhere
>' DoCmd.OpenReport strDocName, acPreview
>
>Exit_Preview_Click:
> Exit Sub
>
>Err_Preview_Click:
> MsgBox Err.Description
> Resume Exit_Preview_Click
>
>End Sub
>
>I added the line Me.Visible = False. Heres why. Add the following code
>to your report module:
>
>Option Compare Database
>Option Explicit
>
>Private Sub Report_Close()
> DoCmd.Close acForm, "frmTest"
>End Sub
>
>Private Sub Report_Open(Cancel As Integer)
> DoCmd.OpenForm "frmTest", , , , , acDialog, "rpt_Test"
>End Sub
>
>Now open your report. You want to open frmTest from your reports
>Open event to make sure frmTest is loaded and filled with dates. That
>way, qryTest can "see" the parameters in frmTest that it needs to
>set rpt_Test's record source. Make sense? Let me know how it works.
>
>Best,
>
>Bob
>
>>From: "Nikola" <Nikola@b...>
>>Reply-To: "Access" <access@p...>
>>To: "Access" <access@p...>
>>Subject: [access] Re: one fuction on more forms
>>Date: Fri, 22 Nov 2002 20:24:14 -0000
>>
>>or to formulate my question:
>>
>>in unbound form i have to field (txtStartDate and txtEndDate)and print
>>button.in button is this
>>code:
>>Private Sub Preview_Click()
>>On Error GoTo Err_Preview_Click
>>
>>Dim strDocName As String
>>Dim strWhere As String
>>Dim strField As String
>>Const USAdate = "\#mm\/dd\/yyyy\#"
>>
>>strDocName = "rpt_test"
>>strField = "TransactionDate"
>>
>>If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
>> MsgBox "Test"
>> Me.txtStartDate.SetFocus
>>Else
>> strWhere = strField & " Between " & Format(Me.txtStartDate, USAdate) _
>> & " And " & Format(Me.txtEndDate, USAdate)
>>
>>End If
>> 'Debug.Print strWhere
>> DoCmd.OpenReport strDocName, acPreview, , strWhere
>>
>>Exit_Preview_Click:
>> Exit Sub
>>
>>Err_Preview_Click:
>> MsgBox Err.Description
>> Resume Exit_Preview_Click
>>
>>End Sub
>>
>>Now I make Query (qryTest)from Table Transaction and in criteria for field
>>"TransactionDate"
>>i put between [forms]![frmTest].[txtStartDate] AND
>>[forms]![frmTest].[txtEndDate]
>>And Source for Report is qryTest. Do i doing right or wrong?
>>
>>Thanks
>>
>>-----Original Message-----
>>From: Bob Bedell [mailto:bobbedell15@m...]
>>Sent: Friday, November 22, 2002 5:56 PM
>>To: Access
>>Subject: [access] Re: one fuction on more forms
>>
>>
>>Just a second thought...
>>
>>For further testing purposes, you can always temporarily change your
>>PC's regional settings and run your code under the new settings.
>>The default American short date format in Windows XP is M/d/yyyy,
>>and the default date separator is /
>>
>>_________________________________________________________________
>>Protect your PC - get McAfee.com VirusScan Online
>>http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
>>
>>
>>
>>
>
>
>_________________________________________________________________
>Help STOP SPAM with the new MSN 8 and get 2 months FREE*
>http://join.msn.com/?page=features/junkmail
>
>
>---
>Change your mail options at http://p2p.wrox.com/manager.asp or to
>unsubscribe send a blank email to
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
Message #14 by "Bob Bedell" <bobbedell15@m...> on Fri, 22 Nov 2002 23:02:33 +0000
|
|
Hi Nikola,
I may have been right the first time. If you are explicitly writing
SQL statements in code you need to force the format conversion. That
part seems to be right. However, if you are using a saved query, Access
may do the conversion for you automatically. For example, Query Design
view shows dates according to your local settings, but the SQL behind
the scenes uses the mm/dd/yyyy format. Play with the saved query
approach a bit and see what happens.
Bob
>From: "Bob Bedell" <bobbedell15@m...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Re: one fuction on more forms
>Date: Fri, 22 Nov 2002 21:23:43 +0000
>
>Oops...I messed up :(
>
>Disregard that last post. Forgot you need you formatting
>function.
>
>Bob
>
>>From: "Bob Bedell" <bobbedell15@m...>
>>Reply-To: "Access" <access@p...>
>>To: "Access" <access@p...>
>>Subject: [access] Re: one fuction on more forms
>>Date: Fri, 22 Nov 2002 20:56:50 +0000
>>
>>Hi Nikola,
>>
>>This is a good way to go. However, if you use a saved query you don't
>>need to set the WHERE clause in your code. I commented out the lines of
>>code you won't need below:
>>
>>Private Sub cmdPreview_Click()
>>On Error GoTo Err_Preview_Click
>>
>>Dim strDocName As String
>>Dim strWhere As String
>>Dim strField As String
>>Const USAdate = "\#mm\/dd\/yyyy\#"
>>
>>strDocName = "rpt_test"
>>strField = "TransactionDate"
>>
>>If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
>> MsgBox "Test"
>> Me.txtStartDate.SetFocus
>>Else
>>' strWhere = strField & " Between " & Format(Me.txtStartDate, USAdate) _
>>' & " And " & Format(Me.txtEndDate, USAdate)
>>Me.Visible = False
>>End If
>>' Debug.Print strWhere
>>' DoCmd.OpenReport strDocName, acPreview
>>
>>Exit_Preview_Click:
>> Exit Sub
>>
>>Err_Preview_Click:
>> MsgBox Err.Description
>> Resume Exit_Preview_Click
>>
>>End Sub
>>
>>I added the line Me.Visible = False. Heres why. Add the following code
>>to your report module:
>>
>>Option Compare Database
>>Option Explicit
>>
>>Private Sub Report_Close()
>> DoCmd.Close acForm, "frmTest"
>>End Sub
>>
>>Private Sub Report_Open(Cancel As Integer)
>> DoCmd.OpenForm "frmTest", , , , , acDialog, "rpt_Test"
>>End Sub
>>
>>Now open your report. You want to open frmTest from your reports
>>Open event to make sure frmTest is loaded and filled with dates. That
>>way, qryTest can "see" the parameters in frmTest that it needs to
>>set rpt_Test's record source. Make sense? Let me know how it works.
>>
>>Best,
>>
>>Bob
>>
>>>From: "Nikola" <Nikola@b...>
>>>Reply-To: "Access" <access@p...>
>>>To: "Access" <access@p...>
>>>Subject: [access] Re: one fuction on more forms
>>>Date: Fri, 22 Nov 2002 20:24:14 -0000
>>>
>>>or to formulate my question:
>>>
>>>in unbound form i have to field (txtStartDate and txtEndDate)and print
>>>button.in button is this
>>>code:
>>>Private Sub Preview_Click()
>>>On Error GoTo Err_Preview_Click
>>>
>>>Dim strDocName As String
>>>Dim strWhere As String
>>>Dim strField As String
>>>Const USAdate = "\#mm\/dd\/yyyy\#"
>>>
>>>strDocName = "rpt_test"
>>>strField = "TransactionDate"
>>>
>>>If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
>>> MsgBox "Test"
>>> Me.txtStartDate.SetFocus
>>>Else
>>> strWhere = strField & " Between " & Format(Me.txtStartDate, USAdate) _
>>> & " And " & Format(Me.txtEndDate, USAdate)
>>>
>>>End If
>>> 'Debug.Print strWhere
>>> DoCmd.OpenReport strDocName, acPreview, , strWhere
>>>
>>>Exit_Preview_Click:
>>> Exit Sub
>>>
>>>Err_Preview_Click:
>>> MsgBox Err.Description
>>> Resume Exit_Preview_Click
>>>
>>>End Sub
>>>
>>>Now I make Query (qryTest)from Table Transaction and in criteria for
>>>field
>>>"TransactionDate"
>>>i put between [forms]![frmTest].[txtStartDate] AND
>>>[forms]![frmTest].[txtEndDate]
>>>And Source for Report is qryTest. Do i doing right or wrong?
>>>
>>>Thanks
>>>
>>>-----Original Message-----
>>>From: Bob Bedell [mailto:bobbedell15@m...]
>>>Sent: Friday, November 22, 2002 5:56 PM
>>>To: Access
>>>Subject: [access] Re: one fuction on more forms
>>>
>>>
>>>Just a second thought...
>>>
>>>For further testing purposes, you can always temporarily change your
>>>PC's regional settings and run your code under the new settings.
>>>The default American short date format in Windows XP is M/d/yyyy,
>>>and the default date separator is /
>>>
>>>_________________________________________________________________
>>>Protect your PC - get McAfee.com VirusScan Online
>>>http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
>>>
>>>
>>>
>>>
>>
>>
>>_________________________________________________________________
>>Help STOP SPAM with the new MSN 8 and get 2 months FREE*
>>http://join.msn.com/?page=features/junkmail
>>
>>
>>---
>>Change your mail options at http://p2p.wrox.com/manager.asp or to
>>unsubscribe send a blank email to
>
>
>_________________________________________________________________
>Add photos to your e-mail with MSN 8. Get 2 months FREE*.
>http://join.msn.com/?page=features/featuredemail
>
>
>---
>Change your mail options at http://p2p.wrox.com/manager.asp or to
>unsubscribe send a blank email to
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
|
|
 |