LogMessages Property
Applies To
QueryDef object.
Description
Sets or returns a value that specifies if the messages returned from a Microsoft Jet-connected ODBC data source are recorded (Microsoft Jet workspaces only).
Note Before you can set or get the value of the LogMessages property, you must create the LogMessages property with the CreateProperty method, and append it to the Properties collection of a QueryDef object.
Settings and Return Values
The setting or return value is a Boolean that is True if ODBC-generated messages are recorded.
Remarks
Some pass-through queries can return messages in addition to data. If you set the LogMessages property to True, the Microsoft Jet database engine creates a table that contains returned messages. The table name is the user name concatenated with a hyphen (-) and a sequential number starting at 00. For example, because the default user name is Admin, the tables returned would be named Admin-00, Admin-01, and so on.
If you expect the query to return messages, create and append a user-defined LogMessages property for the QueryDef object, and set its type to Boolean and its value to True.
Once you've processed the results from these tables, you may want to delete them from the database along with the temporary query used to create them.
Example
This example uses the LogMessages and ReturnsRecords properties to create a pass-through query that will return data and any messages generated by the remote server.
Sub LogMessagesX()
Dim wrkJet As Workspace
Dim dbsCurrent As Database
Dim qdfTemp As QueryDef
Dim prpNew As Property
Dim rstTemp As Recordset
' Create Microsoft Jet Workspace object.
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set dbsCurrent = wrkJet.OpenDatabase("DB1.mdb")
' Create a QueryDef that will log any messages from the
' server in temporary tables.
Set qdfTemp = dbsCurrent.CreateQueryDef("NewQueryDef")
qdfTemp.Connect = _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers"
qdfTemp.SQL = "SELECT * FROM stores"
qdfTemp.ReturnsRecords = True
Set prpNew = qdfTemp.CreateProperty("LogMessages", _
dbBoolean, True)
qdfTemp.Properties.Append prpNew
' Execute query and display results.
Set rstTemp = qdfTemp.OpenRecordset()
Debug.Print "Contents of recordset:"
With rstTemp
Do While Not .EOF
Debug.Print , .Fields(0), .Fields(1)
.MoveNext
Loop
.Close
End With
' Delete new QueryDef because this is a demonstration.
dbsCurrent.QueryDefs.Delete qdfTemp.Name
dbsCurrent.Close
wrkJet.Close
End Sub