Article ID: 147814
Article Last Modified on 3/14/2005
CREATE PROC mod_authors AS
SELECT dbo.authors.* FROM dbo.authors WHERE dbo.authors.state='CA'
UPDATE dbo.authors SET dbo.authors.state='CA'
where dbo.authors.state='UT'
SELECT dbo.authors.* FROM dbo.authors WHERE dbo.authors.state='CA'
This code selects data from the authors table, changes the state for
authors who live in Utah to California, and then selects the data again
mod_authors;
Save this query giving it the name "BatchQuery"; remember to set the
ODBCConnectStr and the ReturnRecords properties appropriately.
Private Sub Command1_Click ()
Dim db As Database
Dim tb As RecordSet
Dim tmpv As Variant
Dim i As Integer, j As Integer
On Error GoTo ErrorHandler
' Open the Microsoft Access version 2.0 .MDB database that contains
' the SQL pass-through query. Be sure to enter the proper directory.
Set db = Workspace(0).OpenDatabase("C:\ACCESS\MULTRES.MDB")
' Loop through tables and delete any temp tables that
' are created by executing the Pass-Through query:
i = 0
Do While i < db.TableDefs.Count
If InStr(UCase$(Trim(db.TableDefs(i).Name)), "TMPTABLE") Then
db.TableDefs.Delete db.TableDefs(i).Name
i = 0
Else
i = i + 1
End If
Loop
' Execute the SQL pass-through query BatchQuery. Because the query
' contains multiple SQL statements, the temporary tables are created
' here.
db.Execute("Select BatchQuery.* into tmpTable from BatchQuery;")
' Refresh the table list:
db.TableDefs.Refresh
' Initialize grid:
Grid1.Rows = 2
Grid1.Cols = 2
Grid1.Row = 1
Grid1.Col = 1
' Loop through all of the tabledefs in the .MDB file and look for the
' ones created by the stored procedure:
For i = 0 To db.TableDefs.Count - 1
If InStr(UCase$(Trim(db.TableDefs(i).Name)), "TMPTABLE") Then
Set tb = db.OpenRecordSet(db.TableDefs(i).Name, dbOpenTable)
' See if this result set has more columns than present:
If Grid1.Cols <= tb.Fields.Count Then
Grid1.Cols = tb.Fields.Count + 1
End If
' Get the column headings:
For j = 0 To tb.Fields.Count - 1
Grid1.Col = j + 1
Grid1.Text = tb.Fields(j).SourceField
Next j
' Load the grid:
Grid1.Rows = Grid1.Rows + 1
Grid1.Row = Grid1.Rows - 1
Do While Not tb.EOF
For j = 0 To tb.Fields.Count - 1
' Check for NULLs:
tmpv = tb.Fields(j).Value: If IsNull(tmpv) Then tmpv = ""
Grid1.Col = j + 1
' Check column width and adjust as necessary.
' Make sure form and grid have the same font properties:
If Grid1.ColWidth(Grid1.Col) < Me.TextWidth(CStr(tmpv)) Then
Grid1.ColWidth(Grid1.Col) = Me.TextWidth(CStr(tmpv))
End If
' Assign the value:
Grid1.Text = UCase$(Trim(CStr(tmpv)))
Next j
' Move to the next record:
Grid1.Rows = Grid1.Rows + 1
Grid1.Row = Grid1.Rows - 1
tb.MoveNext
Loop
' Close current table:
tb.Close
Grid1.Rows = Grid1.Rows + 1
Grid1.Row = Grid1.Rows - 1
End If
Next i
db.Close
Exit Sub
ErrorHandler:
If Err <> 0 Then
MsgBox Error$
End If
Exit Sub
End Sub
Additional query words: 4.00 vb4win vb416 Stored Procedure Result Set ODBC
Keywords: kbhowto kb16bitonly KB147814