freckles81
Board Regular
- Joined
- Apr 7, 2009
- Messages
- 55
Hello all
sorry for this, twice in one day!!
I have a form that I have put together that is allowing the user to select a date using spin buttons and it places the date in the text box, this works fine but when I ask it to place it in the spreadsheet it places it in as a time '00:00.00' and not a date. I know I need to add something in the VB to get it to use a date format but I don't know what i have missed.
I am sure this is really easy but I am just not having any fun with this today
holto is the text box name
this is the info on the spin button
Private Sub UserForm_Activate()
Me.SpinButton2.Min = Int(Now() - 360)
Me.SpinButton2.Max = Int(Now() + 360)
Me.SpinButton2.Value = Int(Now())
SpinButton2_Change
End Sub
Private Sub SpinButton2_Change()
Me.holto.Value = Format(Me.SpinButton2.Value, "dd-mmm-yy")
End Sub
and this is the info in the module
Sub addname()
Dim namejoin As String
Dim propername As String
Dim properfirst As String
Dim properlast As String
Dim dept As String
Dim existflag As String
Dim x As Long
Dim srange As String
Dim holto As Date
andtheresmore:
Load UserForm1
Application.ScreenUpdating = False
startagain:
UserForm1.Show
If UserForm1.firstname.Value = "" Then
MsgBox "User First Name Cannot Be Blank - Please Re Input", vbExclamation, "Agency Personnel - Add Name"
UserForm1.firstname.SetFocus
GoTo startagain:
End If
If UserForm1.lastname.Value = "" Then
MsgBox "User Surname Cannot Be Blank - Please Re Input", vbExclamation, "Agency Personnel - Add Name"
UserForm1.lastname.SetFocus
GoTo startagain:
End If
properfirst = StrConv(UserForm1.firstname.Value, 3)
properlast = StrConv(UserForm1.lastname.Value, 3)
namejoin = properfirst & " "
namejoin = namejoin & properlast
propername = namejoin
Sheets("name").Select
Range("A1").Select
existflag = "N"
Do Until Selection.Value = ""
ActiveCell.Offset(1, 0).Select
If ActiveCell = propername Then
existflag = "Y"
End If
Loop
If existflag = "Y" Then
MsgBox propername & " Already Exists in the Database, Please See Your Administrator", vbCritical, "Agency Personnel - Add Name"
GoTo okthatsitthen
End If
dept = UserForm1.dept.Value
Call unlockit
ActiveCell = propername
ActiveCell.Offset(0, 1).Value = dept
ActiveCell.Offset(0, 2).Value = properfirst
ActiveCell.Offset(0, 3).Value = properlast
ActiveCell.Offset(0, 4).Value = holto
Sheets(dept).Select
Range("A2").Select
Do Until Selection.Value = ""
ActiveCell.Offset(1, 0).Select
Loop
Call unlockit
ActiveCell = propername
Call lockit
Sheets("name").Select
Call unlockit
Range("A1").Select
Selection.End(xlDown).Select
x = ActiveCell.Row
srange = "A2:e" & x
Range(srange).Select
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Key3:=Range("C2"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").Select
Call lockit
'ActiveWorkbook.Save
MsgBox propername & " Has Been Added To The Database", vbInformation, "Agency Personnel"
okthatsitthen:
Unload UserForm1
Sheets("Index").Select
Range("C5").Select
GoTo andtheresmore
End Sub
sorry for this, twice in one day!!
I have a form that I have put together that is allowing the user to select a date using spin buttons and it places the date in the text box, this works fine but when I ask it to place it in the spreadsheet it places it in as a time '00:00.00' and not a date. I know I need to add something in the VB to get it to use a date format but I don't know what i have missed.
I am sure this is really easy but I am just not having any fun with this today
holto is the text box name
this is the info on the spin button
Private Sub UserForm_Activate()
Me.SpinButton2.Min = Int(Now() - 360)
Me.SpinButton2.Max = Int(Now() + 360)
Me.SpinButton2.Value = Int(Now())
SpinButton2_Change
End Sub
Private Sub SpinButton2_Change()
Me.holto.Value = Format(Me.SpinButton2.Value, "dd-mmm-yy")
End Sub
and this is the info in the module
Sub addname()
Dim namejoin As String
Dim propername As String
Dim properfirst As String
Dim properlast As String
Dim dept As String
Dim existflag As String
Dim x As Long
Dim srange As String
Dim holto As Date
andtheresmore:
Load UserForm1
Application.ScreenUpdating = False
startagain:
UserForm1.Show
If UserForm1.firstname.Value = "" Then
MsgBox "User First Name Cannot Be Blank - Please Re Input", vbExclamation, "Agency Personnel - Add Name"
UserForm1.firstname.SetFocus
GoTo startagain:
End If
If UserForm1.lastname.Value = "" Then
MsgBox "User Surname Cannot Be Blank - Please Re Input", vbExclamation, "Agency Personnel - Add Name"
UserForm1.lastname.SetFocus
GoTo startagain:
End If
properfirst = StrConv(UserForm1.firstname.Value, 3)
properlast = StrConv(UserForm1.lastname.Value, 3)
namejoin = properfirst & " "
namejoin = namejoin & properlast
propername = namejoin
Sheets("name").Select
Range("A1").Select
existflag = "N"
Do Until Selection.Value = ""
ActiveCell.Offset(1, 0).Select
If ActiveCell = propername Then
existflag = "Y"
End If
Loop
If existflag = "Y" Then
MsgBox propername & " Already Exists in the Database, Please See Your Administrator", vbCritical, "Agency Personnel - Add Name"
GoTo okthatsitthen
End If
dept = UserForm1.dept.Value
Call unlockit
ActiveCell = propername
ActiveCell.Offset(0, 1).Value = dept
ActiveCell.Offset(0, 2).Value = properfirst
ActiveCell.Offset(0, 3).Value = properlast
ActiveCell.Offset(0, 4).Value = holto
Sheets(dept).Select
Range("A2").Select
Do Until Selection.Value = ""
ActiveCell.Offset(1, 0).Select
Loop
Call unlockit
ActiveCell = propername
Call lockit
Sheets("name").Select
Call unlockit
Range("A1").Select
Selection.End(xlDown).Select
x = ActiveCell.Row
srange = "A2:e" & x
Range(srange).Select
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Key3:=Range("C2"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").Select
Call lockit
'ActiveWorkbook.Save
MsgBox propername & " Has Been Added To The Database", vbInformation, "Agency Personnel"
okthatsitthen:
Unload UserForm1
Sheets("Index").Select
Range("C5").Select
GoTo andtheresmore
End Sub