首页 > 解决方案 > 日期不会出现在列表框的文本框中

问题描述

我想知道是否有人可以帮助我,我有一个数据列表框,当您双击列表框中的行时,所有文本框都会填充列表框中的数据,包括 2 个不同的文本框,其中包含日期但它不显示日期为 DD/MM/YYYY 而不是显示数字。

有人可以帮帮我吗。

下面是代码。

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

If IsNull(Me.ListBox1.Value) Then
MsgBox "Please double click on the name line", vbExclamation, "Select a Name Line"
Else

    If Me.ListBox1.List(Me.ListBox1.ListIndex, 0) <> "" Then
    
    Me.CommandButton1.Enabled = False
     Me.CommandButton2.Enabled = True
   
    Me.TextBox1.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 1)
    Me.TextBox1.Enabled = False
    Me.TextBox1.BackColor = RGB(155, 295, 155)
    
        Me.TextBox2.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 2)
        Me.TextBox2.Enabled = False
        Me.TextBox2.BackColor = RGB(155, 295, 155)
    
    Me.TextBox3.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 3)
    Me.TextBox3.Enabled = False
    Me.TextBox3.BackColor = RGB(155, 295, 155)
   
    
    Me.TextBox5.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 4)
  
    
    Me.TextBox6.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 5)
    Me.TextBox7.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 6)
      
    Me.TextBox8.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 7)
    Me.ComboBox1.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 8)
  
    
    Me.TextBox9.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 9)
        
        ' Textbox10 it is the Date box
        Me.TextBox10.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 10)
        
        Me.TextBox37.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 11)
        Me.TextBox38.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 12)
        Me.TextBox39.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 15)
        
        ' Textbox11 it is the Date box
            Me.TextBox11.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 13)
            Me.TextBox12.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 14)
                    
    Me.TextBox13.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 16)
     Me.TextBox13.Enabled = False
    Me.TextBox13.BackColor = RGB(155, 295, 155)
                    
End If

End If


End Sub

标签: excelvba

解决方案


例如:

Me.TextBox10.Value = Format(Me.ListBox1.List(Me.ListBox1.ListIndex, 10), "DD/MM/YYYY")

推荐阅读