+ Reply to Thread
Results 1 to 5 of 5

TextBox and ListBox Date time Issue

Hybrid View

  1. #1
    Registered User
    Join Date
    01-20-2015
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    36

    TextBox and ListBox Date time Issue

    Copy Record.xlsb

    I have a excel userform with data field loan and return date time (textbox 7 & 8).
    how can I show the field in textbox and listbox with both date and time as shown in "data" sheet col. H & I, i just can show the date only right now

    please help

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,328

    Re: TextBox and ListBox Date time Issue

    Add the code below to format your textboxes (you may need to change the format to your locale settings)

    Private Sub TextBox7_Change()
    Me.TextBox7 = Format(Me.TextBox7, "dd/mm/yyyy h:mm")
    End Sub
    
    Private Sub TextBox8_Change()
    Me.TextBox8 = Format(Me.TextBox8, "dd/mm/yyyy h:mm")
    End Sub

    Add the following five rows to CommandButton9 and also to the Initialize event immediately following the listbox load and to any other Sub that you use to load the listbox.
    Private Sub CommandButton9_Click()
    ListBox1.ColumnWidths = "40;120;20;60;40;100;50;50;50;50;40;50;90;25;25"         'COLUMN WIDTHS OF LISTBOX
    ListBox1.ColumnCount = 15                                                      'Column Count Of Listbox
    ListBox1.List = Sheets("Data").Range("A2:O" & Sheets("data").Cells(Rows.Count, 1).End(xlUp).Row).value
    ListBox1.ListIndex = -1
    TextBox14.value = ListBox1.ListCount
    '*****************add these five rows*****************
    Dim x As Long
    For x = 0 To ListBox1.ListCount - 1
    ListBox1.List(x, 7) = Format(ListBox1.List(x, 7), "dd/mm/yyyy h:mm")
    ListBox1.List(x, 8) = Format(ListBox1.List(x, 8), "dd/mm/yyyy h:mm")
    Next x
    '*******************************************************
    End Sub
    please place all your declared variables immediately after Option Explicit - then run debug and correct all the errors that show.
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  3. #3
    Registered User
    Join Date
    01-20-2015
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    36

    Re: TextBox and ListBox Date time Issue

    thz for your help.

    but how about the listbox? it still no time inside listbox

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,328

    Re: TextBox and ListBox Date time Issue

    Get rid of your UserForm_Activate event it is overriding the Initialize events and cancelling out the format.
    Get rid if your present CommandButton9_Click event and Your Initialize event - then copy/paste the code below - one Sub LOADLIST() is called from the initialize and also if you click Command9


    Private Sub UserForm_Initialize()
    
    '**************ComboBox6************************
    Dim program, status, location, nature As Range
    Dim ws As Worksheet
    Set ws = Worksheets("Lists")
    
    For Each program In ws.Range("Program")
      With Me.ComboBox6
        .AddItem program.value
      End With
    Next program
    
    For Each status In ws.Range("***")
      With Me.ComboBox3
        .AddItem status.value
      End With
    Next status
    
    For Each location In ws.Range("Location")
      With Me.ComboBox4
        .AddItem location.value
      End With
    Next location
    
    For Each nature In ws.Range("Nature")
      With Me.ComboBox5
        .AddItem nature.value
      End With
    Next nature
    
    '** SEARCH COMBOBOX
    With ComboBox1
    .AddItem "Patient Name"
    .AddItem "Index No."
    .AddItem "Location"
    .AddItem "Validation"
    End With
    '**********************************************
    With ComboBox2
    .AddItem "<"
    .AddItem ">"
    .AddItem "="
    End With
    ComboBox2.ListIndex = 0
    TextBox14.value = ListBox1.ListCount
    TextBox15.value = ""
    With lblDone
            .Top = lblRemain.Top + 1
            .Left = lblRemain.Left + 1
            .Height = lblRemain.Height - 2
            .Width = 0
        End With
    lblPct.Visible = False
    LOADLIST
    End Sub
    
    Private Sub CommandButton9_Click()
    LOADLIST
    End Sub
    
    Sub LOADLIST()
    Me.ListBox1.Clear
    ListBox1.ColumnWidths = "40;120;20;60;40;100;100;100;100;50;40;50;90;25;25"         'COLUMN WIDTHS OF LISTBOX
    ListBox1.ColumnCount = 15                                                      'Column Count Of Listbox
    ListBox1.List = Sheets("Data").Range("A2:O" & Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row).value
    ListBox1.ListIndex = -1
    TextBox14.value = ListBox1.ListCount
    '*****************add these five rows*****************
    Dim x As Long
    For x = 0 To ListBox1.ListCount - 1
    ListBox1.List(x, 7) = Format(ListBox1.List(x, 7), "dd/mm/yyyy h:mm")
    ListBox1.List(x, 8) = Format(ListBox1.List(x, 8), "dd/mm/yyyy h:mm")
    Next x
    End Sub

  5. #5
    Registered User
    Join Date
    01-20-2015
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    36

    Re: TextBox and ListBox Date time Issue

    thz so much it ok now
    you are great

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Run-Time Error 380 in code to search for a word in Listbox through a textbox on Userform
    By Arif N. Khan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-11-2023, 01:07 AM
  2. Replies: 7
    Last Post: 11-18-2020, 11:29 AM
  3. [SOLVED] Issue with search and display result on ListBox as you type on a TextBox
    By rakotonirinas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-31-2019, 07:15 AM
  4. VBA - Userform - Listbox validation and Listbox to Textbox
    By stevefisher85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-04-2016, 07:11 AM
  5. [SOLVED] Compile error with coding for date in textbox......2007 to 2010 issue!!!
    By Bflare in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-28-2014, 08:20 AM
  6. Not showing value time in TextBox and ListBox
    By Seeuw in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 12-14-2013, 06:27 AM
  7. [SOLVED] date format changes from listbox and textbox on same sheet
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-04-2013, 03:00 PM

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.6.0 RC 1