Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

getting a date format in text box

RandomGirlRandomGirl Posts: 25Member
I am working on a data entry form that puts the entries into a spreadsheet. For my date box I would like the user to only be able to enter in the dates from 03/01/2003 through 08/01/2006 by using the mm/dd/yyyy format. Below is the source code I have so far. Any help or suggestions would be greatly appreciated! Thanks!

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Excise Tax Data")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row


'check for a blank text box
If Trim(Me.txtName.Value) = "" Then
Me.txtName.SetFocus
MsgBox "Please enter a vendor name"
Exit Sub
End If
If Trim(Me.txtDate.Value) = "" Then
Me.txtDate.SetFocus
MsgBox "Please enter a Date"
Exit Sub
End If
If Trim(Me.txtAccount.Value) = "" Then
Me.txtAccount.SetFocus
MsgBox "Please enter an Account Number"
Exit Sub
End If
If Trim(Me.txtAmount.Value) = "" Then
Me.txtAmount.SetFocus
MsgBox "Please enter an Excise Tax Amount"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtName.Value
ws.Cells(iRow, 2).Value = Me.txtDate.Value
ws.Cells(iRow, 3).Value = Me.txtAccount.Value
ws.Cells(iRow, 4).Value = Me.txtAmount.Value
'clear the data
Me.txtName.Value = ""
Me.txtDate.Value = ""
Me.txtAccount.Value = ""
Me.txtAmount.Value = ""
Me.txtName.SetFocus

'contains running sum on form
Me.txtTotalAmt.Value = ws.Cells(1, 7).Value
End Sub

Comments

  • lionblionb Posts: 1,688Member ✭✭
    : I am working on a data entry form that puts the entries into a spreadsheet. For my date box I would like the user to only be able to enter in the dates from 03/01/2003 through 08/01/2006 by using the mm/dd/yyyy format. Below is the source code I have so far. Any help or suggestions would be greatly appreciated! Thanks!
    :
    what language your code was written on? Reason why I am asking this question is code [blue]' ... txtDate.value'[/blue]. Seems to me txtDate is TextBox control. At the same time, [b]as I know[/b], there is no Value Property for TextBox control in VB 6/.NET. Are you using VBA? If your code is written in VBA or VB.NET, I am not sure that IsDate() and Format() functions will work but you can try. If it is VB 6 those functions must work. Here is my code example. In my case txtDate is Textbox cintrol
    [code]
    If Not IsDate(Trim(Me.txtDate.Text)) Then
    Me.txtDate.SetFocus
    MsgBox "Please enter a Date"
    Exit Sub
    Else
    Text2.Text = Format(txtDate.Text, "MM/DD/YYYY")

    End If
    [/code]
  • RandomGirlRandomGirl Posts: 25Member
    [b][red]This message was edited by RandomGirl at 2006-10-30 12:36:41[/red][/b][hr]
    : I am using VB 6. Thanks


    : : I am working on a data entry form that puts the entries into a spreadsheet. For my date box I would like the user to only be able to enter in the dates from 03/01/2003 through 08/01/2006 by using the mm/dd/yyyy format. Below is the source code I have so far. Any help or suggestions would be greatly appreciated! Thanks!
    : :
    : what language your code was written on? Reason why I am asking this question is code [blue]' ... txtDate.value'[/blue]. Seems to me txtDate is TextBox control. At the same time, [b]as I know[/b], there is no Value Property for TextBox control in VB 6/.NET. Are you using VBA? If your code is written in VBA or VB.NET, I am not sure that IsDate() and Format() functions will work but you can try. If it is VB 6 those functions must work. Here is my code example. In my case txtDate is Textbox cintrol
    : [code]
    : If Not IsDate(Trim(Me.txtDate.Text)) Then
    : Me.txtDate.SetFocus
    : MsgBox "Please enter a Date"
    : Exit Sub
    : Else
    : Text2.Text = Format(txtDate.Text, "MM/DD/YYYY")
    :
    : End If
    : [/code]
    :


Sign In or Register to comment.