Hi all,
I am using a database which displays data from a table on a grid. There is a button which runs a piece of vba to add a new row onto the grid, which is working normally. There is then another button which runs another piece of vba (please see below) which then inserts this data into the table. Currently all the data is entered correctly except that the date is changed as it is input, making it completely wrong. I am not the original programmer of the database and am a little lost in trying to fix this. Any suggestions are gratefully received. The vba code for inserting the data is:
I am using a database which displays data from a table on a grid. There is a button which runs a piece of vba to add a new row onto the grid, which is working normally. There is then another button which runs another piece of vba (please see below) which then inserts this data into the table. Currently all the data is entered correctly except that the date is changed as it is input, making it completely wrong. I am not the original programmer of the database and am a little lost in trying to fix this. Any suggestions are gratefully received. The vba code for inserting the data is:
Code:
Private Sub cmdOverTimeAdd_Click()
Dim i As Long
Dim iRow As Long
Dim colCount As Long
Dim strTemp As String
Dim apos As String
Dim eq As String
Dim dtSym As String
Dim ColName As String
Dim FldName As String
Dim strSQL As String
Dim Comma As String
Comma = ", "
dtSym = "#"
eq = " = "
apos = "'"
strSQL = "INSERT INTO OverTime ("
With msOverTime
iRow = .Row
colCount = (.Cols - 1)
For i = 1 To colCount
If Len(.TextMatrix(iRow, i)) > 0 Then
ColName = Trim(.TextMatrix(0, i))
If i = colCount Then
strSQL = strSQL & ColName
Else
strSQL = strSQL & ColName & Comma
End If
End If
Next i
strTemp = Right(strSQL, 2)
If InStr(strTemp, Comma) <> 0 Then strSQL = Left(strSQL, Len(strSQL) - 2)
strSQL = strSQL & ") VALUES ("
For i = 1 To colCount
If Len(.TextMatrix(iRow, i)) > 0 Then
FldName = Trim(.TextMatrix(iRow, i))
ColName = Trim(.TextMatrix(0, i))
strSQL = strSQL & IIf(InStr(ColName, "Date") <> 0, dtSym & FldName & dtSym & Comma, apos & FldName & apos & Comma)
End If
Next i
strTemp = Right(strSQL, 2)
If InStr(strTemp, Comma) <> 0 Then strSQL = Left(strSQL, Len(strSQL) - 2)
strSQL = strSQL & ")"
Call UpdateAccessDB(strSQL)
strTemp = .TextMatrix(iRow, 1) 'get salarynumber
End With
Call PopulateOverTime(strTemp)
End Sub