When you ask questions about code you have written that is not working the
way you want, it is usually a good idea to post your code so we can see what
you are doing and, hopefully, spot how to correct the problem. Otherwise,
all we can do is to guess at a possible solution. My guess is to assign
this...
CDate("01-" & Replace(txtDate, "-", "-20"))
back to your Range or Cell reference. What it does is fill out the year to
four digits so the 08 is never confused as a day value, add the 01 day value
and concatenate it into a form that CDate can process, thus producing a date
that can be sent back to the worksheet.
Rick
- Show quoted text -
Hi,
My problem is this when I enter the Month in DateCharged Field in my
userform, it is showing the 18-SEP-08 in worksheet. when I enter the
SEP 08 in the DateCharged field, which is not suitable for me,
because I need
only SEP-08 to be display in the worksheet.
I am using the following code in my userform.
Pls help me out.
Thanks
Shahzad
Private Sub cmdClearForm_Click()
Call UserForm_Initialize
End Sub
Private Sub CommandButton3_Click()
' for ok button
ActiveWorkbook.Sheets("DailyIssue").Activate
Range("A5").Select
' to fill up combo box for the category
If ComboCategory.ListIndex = -1 Then
MsgBox "You must choose the category SHAHZAD"
ComboCategory.SetFocus
Exit Sub
End If
'-----------------------------------------------
' to fill up QTY
If txtQuantity = "" Then
MsgBox " you must provide Quantity "
txtQuantity.SetFocus
Exit Sub
End If
' to fill up Unit price
If txtUnitPrice = "" Then
MsgBox " you must provide Unit Price "
txtUnitPrice.SetFocus
Exit Sub
End If
' to fill up DateIssue
If DateIssue = "" Then
MsgBox " You must enter the date, format: 'dd/mmm/yyyy'"
DateIssue.SetFocus
Exit Sub
End If
' to fill up DateCharged
If DateCharged = "" Then
MsgBox " You must enter the Month, format: 'dd/mmm/yyyy'"
DateCharged.SetFocus
Exit Sub
End If
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = DateIssue.Value
ActiveCell.Offset(0, 1) = TxtDescription.Value
ActiveCell.Offset(0, 2) = txtQuantity.Value
ActiveCell.Offset(0, 3) = txtUnitPrice.Value
ActiveCell.Offset(0, 5) = ComboCategory.Value
ActiveCell.Offset(0, 6) = ComboEmployee.Value
ActiveCell.Offset(0, 7) = txtTroubleReport.Value
ActiveCell.Offset(0, 8) = DateCharged.Value
ActiveCell.Offset(0, 9) = txtRemarks.Value
' Ask and Do Procedure
If MsgBox("One record is written, do you have more entries ?",
vbYesNo, "Title") = vbYes Then
Call UserForm_Initialize
Else
Unload Me
End If
End Sub
Private Sub DateIssue_exit(ByVal Cancel As MSForms.ReturnBoolean)
'txtFrom being the text box on the user form where the date is
entered.
' to restrict the date field
If Not IsDate(DateIssue) And Len(DateIssue) > 0 Then
MsgBox "Input must be a date in the format: 'dd/mmm/yyyy'"
Cancel = True
Else
DateIssue = Format(DateIssue, "dd/mmm/yyyy")
End If
End Sub
Private Sub DateCharted_exit(ByVal Cancel As MSForms.ReturnBoolean)
'txtFrom being the text box on the user form where the date is
entered.
' to restrict the date field
If Not IsDate(DateCharged) And Len(DateCharged) > 0 Then
MsgBox "Input must be a date in the format: 'dd/mmm/yyyy'"
Cancel = True
Else
DateIssue = Format(DateCharged, "mmm/yyyy")
End If
End Sub
Private Sub UserForm_Initialize()
Application.EnableEvents = False
DateIssue.Value = ""
TxtDescription.Value = ""
txtQuantity.Value = ""
txtUnitPrice.Value = ""
ComboCategory.Value = ""
ComboEmployee.Value = ""
txtTroubleReport.Value = ""
txtRemarks.Value = ""
DateCharged.Value = ""
DateIssue.SetFocus
Application.EnableEvents = True
End Sub
Private Sub CommandButton4_Click()
' for cancel buton
Unload Me
End Sub
Private Sub CommandButton5_Click()
Call UserForm_Initialize
End Sub
Private Sub TxtUnitPrice_Exit(ByVal Cancel As MSForms.ReturnBoolean)
' to restrict blank entry
If txtUnitPrice.Text = "" Then
MsgBox "Sorry, please enter the Unit Price to proceed..."
Cancel = True
End If
End Sub
Private Sub txtUnitPrice_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
' to restrict entry for Numbers only
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
Interaction.Beep
KeyAscii = 0
End If
End Sub
Private Sub TxtQuantity_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'to restrict blank entry
If txtQuantity.Text = "" Then
MsgBox "Sorry, please enter the Quantity to proceed..."
Cancel = True
End If
End Sub
Private Sub txtQuantity_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
' to restrict entry for Numbers only
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
Interaction.Beep
KeyAscii = 0
End If
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
' Disable the "X" on the userform so that the user can't
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox Prompt:=" Sorry but I can't let you do that. "
End If
End Sub
'Private Sub txtDescription_Change()
'==========================================
'the below code is working but I disable it no need here for it.
' the below code will restrict the Description value to Text not
nomaric
' Validation for "TEXT ONLY" condition for DESCRIPTION
' If TxtDescription = vbNullString Then Exit Sub
' If IsNumeric(TxtDescription) Then
' MsgBox "Sorry, please feed text only"
' TextBox1 = vbNullString
' End If
'End Sub