Populate field number data type
I am don't know how to populate the field name number data type. Code I have below populate all field name into combo box2
Code:
Public cnnACC As ADODB.Connection 'Access Connection
Public rst As ADODB.RecordSet
Dim adoField As ADODB.Field
Public adoCat As ADOX.Catalog 'Catalog
Public adoTbl As ADOX.Table 'Table
Set rst = New ADODB.RecordSet
'Set New connection
Set cnnACC = New ADODB.Connection
If rst.State = adStateOpen Then
rst.Close
End If
Dim strDB, strConn As String
strDB = TextBox1.Text
'String Connection with Database path String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDB & ";Persist Security Info=False"
' Open the connection
cnnACC.Open strConn
Dim sSQL As String
vsRecordSource = ComboBox1.Text
sSQL = "SELECT * FROM [" & vsRecordSource & " ]"
rst.Open sSQL, cnnACC, adOpenDynamic, adLockOptimistic
ComboBox2.Clear
For Each adoField In rst.Fields
ComboBox2.AddItem adoField.Name
If ComboBox2.ListCount > 1 Then ComboBox2.ListIndex = 0
Next
Re: Populate field number data type
Code:
sSQL = "SELECT * FROM [" & vsRecordSource & " ]"
Should be
Code:
sSQL = "SELECT [ColumnNameYouWant] FROM [" & vsRecordSource & " ]"
PS: * means all column
Re: Populate field number data type
Ok I got it.. Anything I miss? I am trying to populate the combo box with all number field data type
Code:
ComboBox2.Clear
For Each adoField In rst.Fields
If adoField.Type = adNumeric Or adoField.Type = adDecimal Or adoField.Type = adSmallInt Or adoField.Type = adDouble Or adoField.Type = adInteger Or adoField.Type = adSingle Then
ComboBox2.AddItem adoField.Name
End If
Next
If ComboBox2.ListCount > 1 Then ComboBox2.ListIndex = 0