Howdy!
I am a newbie VBA'er
Ok so I have built a database with userforms to add info and then update info based on code.
As I am in Aus I need the date format to be correct. I am almost there! However the date switches every time (eg one time it 09/10/13 and then the next time its 10/09/13)
Here's the code
(A basic run-down. You add a code to populate the userform with information, then you can update it to put it back into the database)
[pre]
[/pre]
I like to understand what went wrong so an explanation would be greatly appreciated!! (I learn that way
Thank you!!
I am a newbie VBA'er
Ok so I have built a database with userforms to add info and then update info based on code.
As I am in Aus I need the date format to be correct. I am almost there! However the date switches every time (eg one time it 09/10/13 and then the next time its 10/09/13)
Here's the code
(A basic run-down. You add a code to populate the userform with information, then you can update it to put it back into the database)
[pre]
Code:
Private Sub CommandButton1_Click()
Dim eRow As Long
Dim num As String
num = TextBox10.Value
Dim ws As Worksheet
Set ws = Worksheets("Info")
'error check for Match function
On Error GoTo valueiferror
'find specific row
eRow = Application.WorksheetFunction.Match(num, ws.Range("A:A"), 0)
'copy data to the Userform
Me.TextBox1.Value = ws.Cells(eRow, 2).Value
Me.TextBox2.Value = ws.Cells(eRow, 3).Value
Me.TextBox3.Value = ws.Cells(eRow, 4).Value
Me.TextBox4.Value = Format(ws.Cells(eRow, 5).Value, "DD/MM/YYYY")
Me.TextBox5.Value = Format(ws.Cells(eRow, 6).Value, "DD/MM/YYYY")
Me.TextBox6.Value = ws.Cells(eRow, 7).Value
Me.ComboBox1.Value = ws.Cells(eRow, 13).Value
Exit Sub
valueiferror:
MsgBox "Charge Code not recognised" & Chr(13) & "Entries must be Case Sensitive", vbExclamation
End Sub
Private Sub CommandButton2_Click()
Dim eRow As Long
Dim num As String
num = TextBox10.Value
Dim ws As Worksheet
Set ws = Worksheets("Info")
'find specific row
eRow = Application.WorksheetFunction.Match(num, ws.Range("A:A"), 0)
If IsDate(TextBox4.Value) And IsDate(TextBox5.Value) Then
'copy data to the Excel worksheet
ws.Cells(eRow, 2).Value = Me.TextBox1.Value
ws.Cells(eRow, 3).Value = Me.TextBox2.Value
ws.Cells(eRow, 4).Value = Me.TextBox3.Value
ws.Cells(eRow, 5).Value = Format(ws.Cells(eRow, 5).Value, "DD/MM/YYYY")
ws.Cells(eRow, 6).Value = Format(ws.Cells(eRow, 6).Value, "DD/MM/YYYY")
ws.Cells(eRow, 7).Value = Me.TextBox6.Value
ws.Cells(eRow, 13).Value = Me.ComboBox1.Value
Else
MsgBox "Wrong date values entered. Must be dd/mm/yy", vbExclamation
End If
'Clear data for new entry
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox10.Value = ""
Me.ComboBox1.Value = ""
'Set focus on first box for new entry
Me.TextBox10.SetFocus
Exit Sub
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
I like to understand what went wrong so an explanation would be greatly appreciated!! (I learn that way
Thank you!!