Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date text boxes in the form __/__/__

Status
Not open for further replies.
Mar 2, 2006
37
US
Hello,

I have a problem with my dates field on a form,
I have text boxes that when are clicked, Access puts in this__/__/__ in the text box. I'd like for when a user clicks on the text box, the cursor to start at the very beggining, so in this case the first __/ and not the third __/
and when the date is populated on the first text box, I want the cursor to move to the second text box and again start at the beginning __/
I've never done that before. Can I get any help from you?

My existing code in the form is ;

Private Sub cmdEnter_Click()

Dim strWhere1 As String
Dim strReportName As String

strReportName = "rptmain"

strWhere1 = ""

'Check Requirements
If IsNull(Me.txtDate1) And Not IsNull(Me.txtDate2) Then
MsgBox "Enter a start date", vbExclamation
Exit Sub
ElseIf Not IsNull(Me.txtDate1) And IsNull(Me.txtDate2) Then
MsgBox "Enter an end date.", vbExclamation
Exit Sub
End If

'Date Check
If IsNull(Me.txtDate1) And IsNull(Me.txtDate2) Then
strWhere1 = ""
Else
'strWhere1 = "[tblStatutes.Last_Reviewed_Date] Between #" & Me.txtDate1 & "# And #" & Me.txtDate2 & "#"
'orignal - strWhere1 = "[tblStatutes.Last_Reviewed_Date] Between #" & Me.txtDate1 & "# And #" & Me.txtDate2 & "#" & " OR " & "[tblStatutes.Effective_Date] Between #" & Me.txtDate1 & "# And #" & Me.txtDate2 & "#"

strWhere1 = "[Last_Reviewed_Date] Between #" & Me.txtDate1 & "# And #" & Me.txtDate2 & "#" & " OR " & "[Effective_Date] Between #" & Me.txtDate1 & "# And #" & Me.txtDate2 & "#"
' strWhere1 = "tblStatutes.Last_Reviewed_Date Between #" & Format(Me!txtDate1, "yyyy-mm-dd") & "# And #" & Format(Me!txtDate2, "yyyy-mm-dd") & "#"
End If

'Debug.Print strWhere1

'Combo 1
If IsNull(Me.cboType) Then
strWhere1 = strWhere1
Else
If strWhere1 = "" Then
strWhere1 = "[tblStatutes].[Type] = '" & Me.cboType & "'"
Else
strWhere1 = strWhere1 & " AND [tblStatutes].[Type] = '" & Me.cboType & "'"
End If
End If

'Debug.Print strWhere1

'Combo 2
If IsNull(Me.cboFunction) Then
strWhere1 = strWhere1
Else
If strWhere1 = "" Then
strWhere1 = "[tblStatutes].[Function_Type] = '" & Me.cboFunction & "'"
Else
strWhere1 = strWhere1 & " AND [tblStatutes].[Function_Type] = '" & Me.cboFunction & "'"
End If
End If

'Combo 3
If IsNull(Me.cboExemption_Status) Then
strWhere1 = strWhere1
Else
If strWhere1 = "" Then
strWhere1 = "[tblStatutes].[Exemption_Status] = '" & Me.cboExemption_Status & "'"
Else
strWhere1 = strWhere1 & " AND [tblStatutes].[Exemption_Status] = '" & Me.cboExemption_Status & "'"
End If
End If

'Debug.Print strWhere1

On Error Resume Next
DoCmd.OpenReport strReportName, acViewPreview, , strWhere1

Me.txtDate1 = Null
Me.txtDate2 = Null
Me.cboType = Null
Me.cboFunction = Null
Me.cboExemption_Status = Null

End Sub

Thanks,

Rita
 
Have a look at the SelStart and SelLength properties of the TextBox object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Something like

Code:
[COLOR=green]'to set the focus to the beginning of the field [/color]
Private Sub t1_GotFocus()
t1.SelStart = 0
End Sub

[COLOR=green]'Use the Current Event to turn tabstops on.[/color]
Private Sub Form_Current()
Dim ctl As Control
For Each ctl In Me.Controls
ctl.TabStop = True
Next ctl
End Sub

[COLOR=green]'After Updating, turn the tabstop off.[/color]

Private Sub t1_AfterUpdate()
If Len(t1) > 0 Then
t1.TabStop = False
Else
t1.TabStop = True
End If
End Sub
 
Thanks for your quick response. I did this (see below )and it seems to be working except for when the first text box (date 1) __/__/__ is populated, one has to tab down in order to go down to the next text box (date 2). I'd like for Access to automatically go to the next text box (date 2)once the first text box is filled in.

I did this for both date1 and date2 text boxes,

Private Sub txtDate1_Click()

txtDate1.SelStart = 0
txtDate1.SelLength = 3

End Sub

Private Sub txtDate1_GotFocus()

txtDate1.SelStart = 0
txtDate1.SelLength = 3


Any suggestion


Thanks,

Rita
 
You may consider the AutoTab property of TextBox.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top