D
David Mulholland
I'm using the code to see who is in the LDB of a linked database. I have it
set up so that I select a linked table from a listbox from my Master Form and
then call this function...(original code)
Public Sub WhoIsInLDB()
' Written by Ken Snell (January 31, 2005)
Dim cn As New ADODB.Connection
Dim dbs As DAO.Database
Dim rs As New ADODB.Recordset
Dim strNewDataSource As String, strCNString As String
Dim strCurrConnectString As String
Dim strLinkedTableName As String
strLinkedTableName = Forms![Master Form]![LinkedTable]
Const strDatabaseString As String = "DATABASE="
Const strDataSourceText As String = "Data Source="
On Error GoTo Err_Msg
strCurrConnectString = CurrentProject.Connection
strCNString = Mid(strCurrConnectString, InStr(strCurrConnectString, _
strDataSourceText) + Len(strDataSourceText))
strCNString = Left(strCNString, InStr(strCNString, ";") - 1)
Set dbs = CurrentDb
strNewDataSource = dbs.TableDefs(strLinkedTableName).Connect
strNewDataSource = Mid(strNewDataSource, InStr(strNewDataSource, _
strDatabaseString) + Len(strDatabaseString))
Debug.Print "File containing the data tables: " & strNewDataSource
cn.ConnectionString = Replace(strCurrConnectString, strCNString, _
strNewDataSource, 1, 1, vbTextCompare)
cn.Open
Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
, "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, "", rs.Fields(2).Name,
rs.Fields(3).Name
While Not rs.EOF
Debug.Print rs.Fields(0), rs.Fields(1), rs.Fields(2), rs.Fields(3)
rs.MoveNext
Wend
Exit_Sub:
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
dbs.Close
Set dbs = Nothing
Exit Sub
Err_Msg:
Debug.Print "Error occurred. Error number " & Err.Number & ": " & _
Err.Description
Resume Exit_Sub
End Sub
Modified code...
Forms![Master Form]![LDB_Results] = rs.Fields(0).Name & " " & _
rs.Fields(1).Name & " " & rs.Fields(2).Name & " " & rs.Fields(3).Name
While Not rs.EOF
Forms![Master Form]![LDB_Results] = Forms![Master Form]![LDB_Results] = &
_ rs.Fields(0) & " " & rs.Fields(1) & " " & rs.Fields(2) & " " &
rs.Fields(3)
rs.MoveNext
Wend
What I want to do is send the debug.print comments to a textbox on my main
form, Forms![Master Form]![LDB_Results].
I've played around with it and can only get the first computername from the
Immediate Window to post to that textbox when there are actually multiples.
What am I missing?? It's got to be something in the While/Wend piece but I am
having brain cramps. Any ideas?
set up so that I select a linked table from a listbox from my Master Form and
then call this function...(original code)
Public Sub WhoIsInLDB()
' Written by Ken Snell (January 31, 2005)
Dim cn As New ADODB.Connection
Dim dbs As DAO.Database
Dim rs As New ADODB.Recordset
Dim strNewDataSource As String, strCNString As String
Dim strCurrConnectString As String
Dim strLinkedTableName As String
strLinkedTableName = Forms![Master Form]![LinkedTable]
Const strDatabaseString As String = "DATABASE="
Const strDataSourceText As String = "Data Source="
On Error GoTo Err_Msg
strCurrConnectString = CurrentProject.Connection
strCNString = Mid(strCurrConnectString, InStr(strCurrConnectString, _
strDataSourceText) + Len(strDataSourceText))
strCNString = Left(strCNString, InStr(strCNString, ";") - 1)
Set dbs = CurrentDb
strNewDataSource = dbs.TableDefs(strLinkedTableName).Connect
strNewDataSource = Mid(strNewDataSource, InStr(strNewDataSource, _
strDatabaseString) + Len(strDatabaseString))
Debug.Print "File containing the data tables: " & strNewDataSource
cn.ConnectionString = Replace(strCurrConnectString, strCNString, _
strNewDataSource, 1, 1, vbTextCompare)
cn.Open
Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
, "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, "", rs.Fields(2).Name,
rs.Fields(3).Name
While Not rs.EOF
Debug.Print rs.Fields(0), rs.Fields(1), rs.Fields(2), rs.Fields(3)
rs.MoveNext
Wend
Exit_Sub:
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
dbs.Close
Set dbs = Nothing
Exit Sub
Err_Msg:
Debug.Print "Error occurred. Error number " & Err.Number & ": " & _
Err.Description
Resume Exit_Sub
End Sub
Modified code...
Forms![Master Form]![LDB_Results] = rs.Fields(0).Name & " " & _
rs.Fields(1).Name & " " & rs.Fields(2).Name & " " & rs.Fields(3).Name
While Not rs.EOF
Forms![Master Form]![LDB_Results] = Forms![Master Form]![LDB_Results] = &
_ rs.Fields(0) & " " & rs.Fields(1) & " " & rs.Fields(2) & " " &
rs.Fields(3)
rs.MoveNext
Wend
What I want to do is send the debug.print comments to a textbox on my main
form, Forms![Master Form]![LDB_Results].
I've played around with it and can only get the first computername from the
Immediate Window to post to that textbox when there are actually multiples.
What am I missing?? It's got to be something in the While/Wend piece but I am
having brain cramps. Any ideas?