PDA

View Full Version : Format display in the comboBox



apen
05-31-2008, 04:14 AM
Dear all,

Would anyone help me solve my problem- the Datevalue display in the comboBox will change to the format of string when I selected. How can I fix it when I selected the date and display the same.
Please refer to my attached file and press the Data Entry (Command Button).

Thanks,
Apen

Aussiebear
05-31-2008, 04:52 AM
Could it be possible to get the string value selected to drop into a list (a range on another sheet first), then have this range formatted to the date format you require? The combo box could then pick up this range as its source.

Norie
05-31-2008, 05:01 AM
apen

How can we possibly help you?

The code in the workbook you posted is password protected and constantly errors anyway.:huh:

apen
05-31-2008, 06:03 AM
Dear Aussiebear,

If I put the value in form of string, the data inputting to the wokrsheets( " Attendance " and could not calculate, so would you suggest another way.

apen

apen
05-31-2008, 06:07 AM
I am sorry for that, let me try to post any thread with no password., but anyway it is not related to password because the comboBox's value is refer to the data list in worksheet("Select")

The VBA is:

Userform2.comboBox1.RowSource =Sheets("Select")!Name

Apen

apen
05-31-2008, 06:12 AM
I have re-attached the file without password.

mdmackillop
05-31-2008, 06:33 AM
Private Sub ComboBox2_Click()
Dim ra As Variant
ra = ComboBox2.Value
Application.ScreenUpdating = True
ComboBox2 = Format(ComboBox2, "dd-mmm-yy")
End Sub

apen
05-31-2008, 06:40 AM
Dear Mdamackillop,

the code still having an error on the " Format"

mdmackillop
05-31-2008, 08:04 AM
Check for missing VBA references. Tools/References. Uncheck any that are marked Missing

david000
05-31-2008, 09:58 PM
ComboBox2 = Format(ComboBox2, "dd-mmm-yy")

As a last resort try this
Application.WorksheetFunction.Text(ComboBox2, "dd-mmm-yy")

apen
06-01-2008, 02:37 AM
It does not work, but I try to change it into listbox instead of comboBox, it can display the date when selected, however, the date value could not input automatically into worksheet ("Attendance")

Could any one please help !

mdmackillop
06-01-2008, 03:25 AM
It does not work
This statement is of no value. What does not work? Which line of code? What error message? What result?
If you want us to spend time helping, you need to invest time providing useful information.

Norie
06-01-2008, 05:22 AM
Check for missing VBA references. Tools/References. Uncheck any that are marked Missing
Did you ever do this?

apen
06-01-2008, 06:05 AM
I am sorry, how can I check the missing VBA reference. ....
I paste my VBA as follow : Please correct me where should be re-write.

For command button ( Data Entry)
Private Sub CommandButton2_Click()
UserForm2.ComboBox1.RowSource = "select!name"
UserForm2.ComboBox2.RowSource = "select!dateB"
UserForm2.ComboBox3.RowSource = "select!DateE"
UserForm2.Show
End Sub

Thanks,
Apen

apen
06-01-2008, 06:10 AM
Dear mdmackillop,

even I re-write the code as :



VBA:
ComboBox2 = Format(ComboBox2, "dd-mmm-yy")

VBA tags courtesy of www.thecodenet.com (http://www.thecodenet.com/)


As a last resort try this




VBA:
Application.WorksheetFunction.Text(ComboBox2, "dd-mmm-yy")

VBA


The "date" display in the comboBox is still not in date format but a value, so I reply " it does work"

apen

mikerickson
06-01-2008, 08:07 AM
The ActiveX controls prevent me from testing, but..

My thought is:
1) ComboBox2.Value is a string,
2) Format(someString,"dd-mmm-yy") = someString, therefore ComboBox2.Value should be converted to a number.ComboBox2.Value = Format(DateValue(ComboBox2.Value),"dd-mmm-yy")might solve the issue.

mdmackillop
06-01-2008, 08:13 AM
I am sorry, how can I check the missing VBA reference. ....


In the VBE click Tools/References. Are any marked "Missing"?