A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi again Adrian,
My apologies for the delay in answering but I have been quite busy with other stuff.
I am not able to use your example workbook. Too many problems with the Arabic language.
Your comment: formatting and shows times over 24 hours when the data comes back to the form - even if I try and add a format to the 'Edit' script the format is lost an the value if over 24 hours shows zero in this format 00:00
Edit the following line and use the Worksheet Text Function to convert in lieu of the VBA Format function as per my previous advice in my example workbook.
From Private Sub cmdedit_Click()
Me.txtfirefighting.Value = Format(Me.LstDatabase.List(Me.LstDatabase.ListIndex, 3), "'hh:mm'")
Replace above line with following line.
Me.txtfirefighting = WorksheetFunction.Text(Me.LstDatabase.List(Me.LstDatabase.ListIndex, 3), "[hh]:mm")
See the following code examples between the asterisk lines (in two places in the code) for saving a TextBox d/m/y date to the worksheet. Code example is extracted from your Sub Submit and only one TextBox edited to provide an example of converting a text box value in d/m/y format to a date value on the worksheet.
I don't know why your dates show as m/d/y in your formula bar. On my computer, irrespective of the date NumberFormatting in the cells, the date in my formula bar still displays in d/m/y.
Sub Submit()
Dim sh As Worksheet
Dim irow As Long
'***************************************************************************************************
Dim arrSplit As Variant 'Add this line to dimension the array variable for the Split function
Dim dteFinishDate As Date 'Add this line to dimension the Date Variable
'***************************************************************************************************
Set sh = ThisWorkbook.Sheets("Database")
If frmincident.txtRowNumber.Value = "" Then
irow = [Counta(Database!A:A)] + 1
Else
irow = frmincident.txtRowNumber.Value
End If
With sh
.Cells(irow, 1) = "=Row()-2" 'Dynamic Serial Number
.Cells(irow, 2) = frmincident.txtcomment.Value
.Cells(irow, 3) = frmincident.cmbdelay.Value
.Cells(irow, 4) = frmincident.txtfirefighting.Value
.Cells(irow, 5) = frmincident.txttimefinished.Value
'********************************************************************************************************************
.Cells(irow, 6) = frmincident.txtdatefinished.Value 'Replace Date lines like this with code like the following.
'Split the text finish date at the slashes and assign each value (Day, Month, Year) to a zero base array
arrSplit = Split(frmincident.txtdatefinished, "/")
'Assign Finish Date to a date variable using DateSerial function and the array elements
dteFinishDate = DateSerial(arrSplit(2), arrSplit(1), arrSplit(0))
'Assign the Date Variable to the cell on the worksheet.
.Cells(irow, 6) = dteFinishDate
'If column on the worksheet is preformatted with NumberFormat "dd/mm/yyyy" then following line should not be required
.Cells(irow, 6).NumberFormat = "dd/mm/yyyy"
'***********************************************************************************************************************
As a little extra interesting information, irrespective of the regional date format, VBA code still appears to use m/d/y format for dates. Test the following example for hard coding a date into VBA code and assigning to a date variable. Note the date is entered in d/m/y format and observe what occurs with the date immediately after entering it into the VBA editor.
Sub TestDates()
Dim dteExample As Date
dteExample = #15/4/2020#
End Sub