Thanks Joe for some heads up. I have code here and also try to implement listbox(cmbtable) to get the tables. i know there are flaws in code itself, and some error like, (cmbtable.clear). help me to improvise the code and fix my problem. PLEASE.
HERE IS MY CODE.
Private Sub cmdShowFiles_Click()
Dim cnn As ADODB.Connection 'Don't instantiate in the declaration or ...
Dim rs As ADODB.Recordset '... you won't be able to reclaim the allocated memory without rebooting
Dim adocmd As ADODB.Command
Dim invalid As Integer
Dim sDatabase As String
Dim msaof As MSA_OPENFILENAME
Dim sFileName As String
On Error GoTo Err_CmdShowFiles_Click
txtSource.Value = ""
msaof.strFilter = MSA_CreateFilterString("Access files (*.mdb,*.mde)", "*.mdb;*.mde")
sFileName = MSA_GetOpenFileName(msaof)
If Trim(Len(sFileName)) <> 0 Then
txtSource.Value = msaof.strFullPathReturned
sFileName = ""
End If
Exit_CmdShowFiles_Click:
Exit Sub
Err_CmdShowFiles_Click:
MsgBox Err.Number & " " & Err.Description, vbCritical, "CIMS"
Resume Exit_CmdShowFiles_Click
End Sub
Private Sub Command5_Click()
' command button to browse the same database and ("possibly" 'which i am trying to do) list tables in box.
' code to open the CommonDialog box and let user choose a .mdb file
Dim msaof As MSA_OPENFILENAME
Dim sFileName As String
txtSource.Value = ""
msaof.strFilter = MSA_CreateFilterString("Access files (*.mdb,*.mde)", "*.mdb;*.mde")
sFileName = MSA_GetOpenFileName(msaof)
If Trim(Len(sFileName)) <> 0 Then
txtSource.Value = msaof.strFullPathReturned
sFileName = ""
End If
'put the file name into sDatabase
Set cnn = New ADODB.Connection 'this is where you instantiate
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= txtsource.value ;Persist Security Info=False" 'substitute your connection string
cnn.OpenSchema adSchemaTables
Set rs = New ADODB.Recordset
Set rs = cnn.OpenSchema(adSchemaTables)
cmbtable.Clear 'clear the combobox out
cmbtable.Sorted = True 'alpha sort the table names to make it easier for your user
Do While Not rs.EOF
If Not Left$(rs.Fields("TABLE_NAME").Value, 1) = "~" Then
cmbtable.AddItem rs.Fields("TABLE_NAME").Value
End If
rs.MoveNext
Loop
rs.close
Set rs = Nothing 'reclaim the memory here
cnn.close
Set cnn = Nothing
End Sub