Hello,
I'm trying to run the following code and get type mismatch 13 error
Basically, i'm getting the 3rd field name along in table "ImportedTable", put that value on Combo3 and try run a transpose on the table. The field names (dates) in the transposed table get generated based on the value of Combo3.
The error points to the line:
FieldName = Format(Me.Combo3 + (7 * (i - 1)), "dd-mmm-yyyy")
the fieldname is a string...
how do i do about fixing this one?
I'm trying to run the following code and get type mismatch 13 error
Basically, i'm getting the 3rd field name along in table "ImportedTable", put that value on Combo3 and try run a transpose on the table. The field names (dates) in the transposed table get generated based on the value of Combo3.
The error points to the line:
FieldName = Format(Me.Combo3 + (7 * (i - 1)), "dd-mmm-yyyy")
the fieldname is a string...
how do i do about fixing this one?
Code:
Private Sub cmdAppend_Click()
Dim Con As ADODB.Connection
Set Con = CurrentProject.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
sql = "select * from ImportedTable"" "
With rs
.ActiveConnection = Con
.Open (sql)
End With
Combo3.Value = rs.Fields(rs.Fields.Count - 74).Name
End Sub
Private Sub Command5_Click()
Dim db As DAO.Database
Dim tblDef As DAO.TableDef
Dim sql As String
Dim FieldName As String
Dim i As Integer
Dim j As Integer
Set db = CurrentDb
Set tblDef = db.TableDefs("ImportedTable")
' delete any old records from NewTable.
db.Execute "Delete * from [NewTable]"
' append records to NewTable from ImportedTable.
i = 1
For i = i To 40
j = i + 2
FieldName = Format(Me.Combo3 + (7 * (i - 1)), "dd-mmm-yyyy")
sql = "Insert Into [NewTable] " & _
"Select [ImportedTable].[EmployeeID], [ImportedTable].[ProjectID],#" & _
FieldName & "# as [Week], [" & _
tblDef.Fields(j).Name & "] as [Workload] " & _
"from [ImportedTable]"
db.Execute sql
Next i
MsgBox "Records appended from ImportedTable to NewTable."
Set tblDef = Nothing
Set db = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub
Last edited: