Connecting Tech Pros Worldwide Forums | Help | Site Map

Ms Access Reset a date range to default values

anoble1's Avatar
Newbie
 
Join Date: Jul 2008
Posts: 9
#1: Mar 10 '09
Hey I am wanting to reset a date range to lets say 1/1/2008 - 12/31/2008.
So when I click on reset i want it to bring those values up and limit everything by them. That way it brings up every record. Right now it doesn't seem to work it clears out every record and the dates don't change. It changes the date but does not Requery the form. So no dates populate.

Here is my code so far:
Expand|Select|Wrap|Line Numbers
  1. cmdReset_Click()
  2.  
  3. Recordsource....................................................
  4.  
  5. cmbName.Value = ""
  6. cmbLocation.Value = ""
  7. txtLowDate.Value = "1/1/2008"
  8. txtHighDate. = "12/31/2008"
  9.  
  10. End Sub

ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,219
#2: Mar 10 '09

re: Ms Access Reset a date range to default values


Quote:

Originally Posted by anoble1 View Post

Hey I am wanting to reset a date range to lets say 1/1/2008 - 12/31/2008.
So when I click on reset i want it to bring those values up and limit everything by them. That way it brings up every record. Right now it doesn't seem to work it clears out every record and the dates don't change. It changes the date but does not Requery the form. So no dates populate.

Here is my code so far:

cmdReset_Click()

Recordsource...................................... ..............

cmbName.Value = ""
cmbLocation.Value = ""
txtLowDate.Value = "1/1/2008"
txtHighDate. = "12/31/2008"

End Sub

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. Dim dteLow As Variant
  3. Dim dteHigh As Variant
  4.  
  5. dteLow = Me![txtLowDate]
  6. dteHigh = Me![txtHighDate]
  7.  
  8. 'Must have Values in both Text Boxes
  9. If Not IsNull(dteLow) And Not IsNull(dteHigh) Then
  10.   'They must both be Valid Dates
  11.   If IsDate(dteLow) And IsDate(dteHigh) Then
  12.     strSQL = "Select * From TableName Where TableName.[DateField] Between #" & _
  13.               CDate(dteLow) & "# And #" & CDate(dteHigh) & "#;"
  14.       Me.RecordSource = strSQL
  15.   Else
  16.     'Just to indicate that 1 or more Fields does not contain a Valid Date, not needed
  17.   End If
  18. Else
  19.   'Just to indicate that 1 or both Fields are Null, not needed
  20. End If
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#3: Apr 4 '09

re: Ms Access Reset a date range to default values


It seems like you need to requery whatever it is that you want to reflect the new range. Your question is not very clear on what that is so I'll leave that to you.

Welcome to Bytes!
Reply

Tags
cmbreset, ms access, reset


Similar Microsoft Access / VBA bytes