+ Reply to Thread
Results 1 to 5 of 5

Thread: Automatically Inserting Date in Form

  1. #1
    Registered User
    Join Date
    07-23-2010
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    17

    Automatically Inserting Date in Form

    Hello!

    I have created a spreadsheet on excel and a user form automatically pops up. The first entry is "Date". I was wondering if there is anyway to change my current code (see below) so that the current date is automatically entered on each new entry in order to save the user time.

    Pleaseee help (:

    Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Tasks")
    
    'find first empty row in database
    iRow = ws.Cells(Rows.Count, 1) _
      .End(xlUp).Offset(1, 0).Row
    
    
    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.txtDate.Value
    ws.Cells(iRow, 2).Value = Me.cboTaskLead.Value
    ws.Cells(iRow, 3).Value = Me.txtTaskName.Value
    ws.Cells(iRow, 4).Value = Me.txtProject.Value
    ws.Cells(iRow, 5).Value = Me.txtTaskDescription.Value
    ws.Cells(iRow, 6).Value = Me.cboPriority1.Value
    ws.Cells(iRow, 7).Value = Me.cboPriority2.Value
    
    
    'clear the data
    Me.txtDate.Value = ""
    Me.cboTaskLead.Value = ""
    Me.txtTaskName.Value = ""
    Me.txtTaskDescription.Value = ""
    Me.txtTaskDescription.Value = ""
    Me.cboPriority1.Value = ""
    Me.cboPriority2.Value = ""
    
    
    End Sub

  2. #2
    Forum Contributor
    Join Date
    03-10-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003
    Posts
    132

    Re: Automatically Inserting Date in Form

    You could try setting the object before you show the userform -

    UserForm1.TextBox1 = Format(Now, "dd/mm/yyyy")
    Dave H

  3. #3
    Forum Contributor
    Join Date
    03-10-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003
    Posts
    132

    Re: Automatically Inserting Date in Form

    Sorry JessFace, bit hasty of me there, i shouldn't try multitasking.

    Ignoremy previous post and add the following to the sub that shows your userform -

        Dim Today_Dt As Variant
        Today_Dt = Format(Now, "dd/mm/yyyy")
        UserForm1.TextBox1 = Today_Dt
    Sorry about that

    Dave H

  4. #4
    Registered User
    Join Date
    07-23-2010
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Automatically Inserting Date in Form

    Hi Dave,

    I am a bit confused as to wear to place those three lines of code that you gave me - I put them after this:

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

    Also, when I did put the code, the code
    Today_Dt
    was highlighted and i got "Compile Error: User-defined type not defined" message.

    Any idea if i need to change anything?

  5. #5
    Registered User
    Join Date
    07-23-2010
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Automatically Inserting Date in Form

    Nevermind,I realized i entered it in the wrong place and i tweaked your code just a bit and it worked.

    Thanks a million!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0