Hi,
I adapted a user form (with permission
) which has been working really well until I discovered the issue with UK and US date formatting.
In brief, the form has many text boxes which is used to enter data into a spreadsheet. What I noticed on the 01/12/16 is that excel would switch the date around to 12/01/16 and enter that into the spreadsheet. I got around that by editing the VBA to format the text boxes into UK style dates before adding to the spreadsheet.
After the data is added, I have a lookup function on the form where it re-calls the rows data by a search function and populates the data into the relevant text boxes. At this point excel is looking at the dates in the spreadsheet and switching them to US format. I've tried adding formatting into the VBA again at this point but it doesn't work, I guess because it's already pulled the data in.
I'm wondering if I could please ask for someone's help to see if there is a fix in the short bit of VBA shown below rather than reworking the whole thing.
To explain some of the elements to the code. Cnum = 39 columns in total, text boxes are labelled reg1, reg2 and so on.
Thanks
Private Sub lstLookup_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'declare the variables
Dim cVRM As String
Dim I As Integer
Dim findvalue
'error block
On Error GoTo errHandler:
'get the select value from the listbox
For I = 0 To lstLookup.ListCount - 1
If lstLookup.Selected(I) = True Then
cVRM = lstLookup.List(I, 0)
End If
Next I
'find the VRM
Set findvalue = Sheet2.Range("E:E").Find(What:=cVRM, LookIn:=xlValues).Offset(0, -2)
'add the database values to the userform
cNum = 39
For X = 1 To cNum
Me.Controls("Reg" & X).Value = findvalue
Set findvalue = findvalue.Offset(0, 1)
Next
'disable adding
Me.cmdAdd.Enabled = False
Me.cmdEdit.Enabled = True
'error block
On Error GoTo 0
Exit Sub
errHandler::
MsgBox "An Error has Occurred " & vbCrLf & "The error number is: " _
& Err.Number & vbCrLf & Err.Description & vbCrLf & _
"Please notify the administrator"
End Sub
I adapted a user form (with permission
In brief, the form has many text boxes which is used to enter data into a spreadsheet. What I noticed on the 01/12/16 is that excel would switch the date around to 12/01/16 and enter that into the spreadsheet. I got around that by editing the VBA to format the text boxes into UK style dates before adding to the spreadsheet.
After the data is added, I have a lookup function on the form where it re-calls the rows data by a search function and populates the data into the relevant text boxes. At this point excel is looking at the dates in the spreadsheet and switching them to US format. I've tried adding formatting into the VBA again at this point but it doesn't work, I guess because it's already pulled the data in.
I'm wondering if I could please ask for someone's help to see if there is a fix in the short bit of VBA shown below rather than reworking the whole thing.
To explain some of the elements to the code. Cnum = 39 columns in total, text boxes are labelled reg1, reg2 and so on.
Thanks
Private Sub lstLookup_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'declare the variables
Dim cVRM As String
Dim I As Integer
Dim findvalue
'error block
On Error GoTo errHandler:
'get the select value from the listbox
For I = 0 To lstLookup.ListCount - 1
If lstLookup.Selected(I) = True Then
cVRM = lstLookup.List(I, 0)
End If
Next I
'find the VRM
Set findvalue = Sheet2.Range("E:E").Find(What:=cVRM, LookIn:=xlValues).Offset(0, -2)
'add the database values to the userform
cNum = 39
For X = 1 To cNum
Me.Controls("Reg" & X).Value = findvalue
Set findvalue = findvalue.Offset(0, 1)
Next
'disable adding
Me.cmdAdd.Enabled = False
Me.cmdEdit.Enabled = True
'error block
On Error GoTo 0
Exit Sub
errHandler::
MsgBox "An Error has Occurred " & vbCrLf & "The error number is: " _
& Err.Number & vbCrLf & Err.Description & vbCrLf & _
"Please notify the administrator"
End Sub
Last edited: