A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Filter SubFrom from Main Form using date



 
 
Thread Tools Display Modes
  #1  
Old May 13th, 2010, 04:14 PM posted to microsoft.public.access.forms
StonyfieldRob
external usenet poster
 
Posts: 6
Default Filter SubFrom from Main Form using date

Neither form is bound and only the subform is pulling data from a table.

Would like to enter a date on the main form [Date1].

The subform would then show all data with a start date [SDate] less than
[Date1].
And an end date [EDate] great than [Date1].
  #2  
Old May 14th, 2010, 02:55 AM posted to microsoft.public.access.forms
Jeanette Cunningham
external usenet poster
 
Posts: 2,190
Default Filter SubFrom from Main Form using date

Here's some sample code to get you started.

Private Sub FilterTheSubform
Dim strWhere As String

Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for dates in a
JET query string.


'Date field example. Use the format string to add the # delimiters and get
the right international format.
If Not IsNull(Me.[Date 1]) Then
strWhere = strWhere & "([SDate] = " & Format(Me.[Date 1],
conJetDate) & ") AND "
End If

'Another date field example. Use "less than the next day" since this
field has times as well as dates.
If Not IsNull(Me.[Date 1]) Then 'Less than the next day.
strWhere = strWhere & "([EDate] " & Format(Me.[Date 1] + 1,
conJetDate) & ")"
End If


With Me.SubformControlName.Form
.Filter = strWhere
.FilterOn = True
End With

End Sub


Note: replace my object names with your own.
For a more complete understanding of how to create a search screen, download
this sample db.
http://allenbrowne.com/ser-62.html


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


"StonyfieldRob" wrote in message
...
Neither form is bound and only the subform is pulling data from a table.

Would like to enter a date on the main form [Date1].

The subform would then show all data with a start date [SDate] less than
[Date1].
And an end date [EDate] great than [Date1].



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:41 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.