This post is part of the series on VBA Snippets.
In yesterdays post, I covered adding an ODBC connection to Microsoft Dynamics GP VBA for use n windows or reports. The below is an example of a SQL query using the ODBC connection.
SOPType
and SopNUmber
(highlighted) are fields from a window added to the VBA.
This example retries a list of fields from the Sales Transaction Amounts Work (SOP10200) table.
Dim objRS As ADODB.RecordSet
Set objRS = New ADODB.RecordSet
Set objRS.ActiveConnection = madoConn
sSQL = "SELECT * FROM SOP10200 WHERE SOPTYPE = " & SOPType & " AND SOPNUMBE = '" & SOPNumber & "'"
objRS.Source = sSQL
objRS.Open
If objRS.State = adStateOpen Then
If Not (objRS.BOF Or objRS.EOF) Then
objRS.MoveFirst
Do While Not objRS.EOF
' your code goes here; reference fields using objRS.fields("fieldname"))
objRS.MoveNext
Loop
End If
objRS.Close
End If
Set objRS = Nothing
Click to show/hide the VBA Snippets Series Index
VBA Snippets |
---|
Sleep |
Execute URL or Application |
Adding an SQL ODBC Connection in Microsoft Dynamics GP |
Select Records from Microsoft Dynamics ODBC Connection |
Open a File for Appending |
What should we write about next?
If there is a topic which fits the typical ones of this site, which you would like to see me write about, please use the form, below, to submit your idea.
Looking for support or consultancy with Microsoft Dynamics GP?
I no longer work with Microsoft Dynamics GP, but the last company I worked for was ISC Software in the UK; if you’re looking for support or consultancy services with Microsoft Dynamics GP you can contact them here.