The_Kurgan
Active Member
- Joined
- Jan 10, 2006
- Messages
- 270
Hi all!
I am attempting to create a table based on a selection that the user chooses. Available to the user is the list of fields from another Access table. The new table will basically contain that chosen field and the associated type (Text, Date, or Double).
Here is my code:
The error I'm getting is "No field defined--cannot append TableDef or Index." The strange thing is that it seems to be happening on one date field. All other fields seem to work (including other date fields). I've double-checked the DataType in the table itself and it's the same as other date fields.
I hope this makes sense. I'd love to see what y'all come up with. TIA!
I am attempting to create a table based on a selection that the user chooses. Available to the user is the list of fields from another Access table. The new table will basically contain that chosen field and the associated type (Text, Date, or Double).
Here is my code:
Code:
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim myTable As DAO.TableDef
Dim myField As DAO.Field
Dim myProp As DAO.Property
'variables
fld = Me.List7.Value
Op = Me.List9.Value
FldAndOp = fld & " " & Op
'Get field type of field chosen by user (found in My_Data table)
Set rs = db.OpenRecordset("My_Data")
My_My_Data_Tbl = TypeName(rs.Fields(fld).Value)
'Create table with field name + operator and give the field the proper field type
With myTable
If My_My_Data_Tbl = "Double" Then
.Fields.Append .CreateField(FldAndOp, dbDouble)
ElseIf My_My_Data_Tbl = "Date" Then
.Fields.Append .CreateField(FldAndOp, dbDate)
ElseIf My_My_Data_Tbl = "String" Then
.Fields.Append .CreateField(FldAndOp, dbText)
End If
End With
db.TableDefs.Append myTable '!!!!!!!!!!!!!!!!!!!!!!!! THIS LINE GIVES ME THE ERROR !!!!!!!!!!!!!!!!!!!!!!!!
Set myField = myTable.Fields(FldAndOp)
The error I'm getting is "No field defined--cannot append TableDef or Index." The strange thing is that it seems to be happening on one date field. All other fields seem to work (including other date fields). I've double-checked the DataType in the table itself and it's the same as other date fields.
I hope this makes sense. I'd love to see what y'all come up with. TIA!