Hi All
Just trying to teach myself a little VBA. I have created a user form and when the date is entered in dd/mm/yyyy format it unloads to the database as mm/dd/yyyy I have searched around and tried differing code but to no use any help would be much appreciated I have pasted my attempt below (txt.date) ...no laughing
Just trying to teach myself a little VBA. I have created a user form and when the date is entered in dd/mm/yyyy format it unloads to the database as mm/dd/yyyy I have searched around and tried differing code but to no use any help would be much appreciated I have pasted my attempt below (txt.date) ...no laughing
Code:
Private Sub cmdadd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a part number
If Trim(Me.txtclient.Value) = "" Then
Me.txtclient.SetFocus
MsgBox "Please enter client name"
Exit Sub
End If
'copy the data to the database
'use protect and unprotect lines,
' with your password
' if worksheet is protected
With ws
' .Unprotect Password:="password"
.Cells(iRow, 1).Value = Me.txtclient.Value
.Cells(iRow, 2).Value = Me.txtname.Value
.Cells(iRow, 3).Value = Me.txtphone.Value
.Cells(iRow, 4).Value = Me.txtad.Value
.Cells(iRow, 5).Value = Me.txtadcolumn.Value
.Cells(iRow, 6).Value = Me.txtcost.Value
.Cells(iRow, 7).Value = Me.txtdate.Value
.Cells(iRow, 8).Value = Me.txtrep.Value
.Cells(iRow, 9).Value = Me.txtsection.Value
.Cells(iRow, 10).Value = Me.txtspec.Value
' .Protect Password:="password"
End With
'clear the data
Me.txtclient.Value = ""
Me.txtname.Value = ""
Me.txtphone.Value = ""
Me.txtad.Value = ""
Me.txtadcolumn.Value = ""
Me.txtcost.Value = ""
Me.txtdate.Value = ""
Me.txtrep.Value = ""
Me.txtsection.Value = ""
Me.txtspec.Value = ""
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Last edited by a moderator: