Hello,
I'm trying to create a MS Access Table using VBA through a form...
The form has a combo box called cboCategory and a list-box called lstDrugs.
I want to create a table where the name of the tbl appears as "tbl + cboCategory.value + Date" and add an ID field followed by the drugs selected as the column names...
How can I accomplish that? I started on the code below, but not sure how it would work
Private Sub cmdCreateTbl_Click()
Dim dbs As Database
Dim tbl As TableDef
Dim fld As Field
Dim tblName As String
Dim intIndex As Integer
Set dbs = CurrentDb
tblName = "tbl" & Me.cboCategory.Value & "_" & Date
Set tbl = dbs.CreateTableDef(tblName)
For intIndex = 0 To Me.lstDrugs.ListCount - 1
Set fld = tbl.CreateField(Me.lstDrugs.Selected(intIndex), dbText)
Next
tbl.Fields.Append fld
dbs.TableDefs.Append tbl
dbs.TableDefs.Refresh
End Sub
Bookmarks