Discussion Locked

Access reports through VB6

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am wanting to create dynamic reports by passing a SQL string from VB6 to an access query and then calling a MS Access report from VB6 that is linked to the query I have just passed through. Is this possible and if so can someone please provide me with a code example for it.Thanks

2 replies

by miss kitty

Here is an example of the syntax showing the passing of parameters (values in vb fields) to an Access query:

Dim objConn As New ADODB.Connection
Dim objCmd As New ADODB.Command
Dim objRS As New ADODB.Recordset
Dim objParam As ADODB.Parameter
Dim count As Integer

'set up the database pointer
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=E:\ACCESS\CONTRACT HAULERS\HAULER.mdb;User ID=ADMIN"
objRS.CursorType = adOpenDynamic
objRS.LockType = adLockOptimistic

'setting the Active Connection for the command object
objCmd.ActiveConnection = objConn

'Providing the query name as commandtext
objCmd.CommandText = "[SINGLE TICKET QUERY]"
objCmd.CommandType = adCmdStoredProc

'create the parameter and populate it
Set objParam = objCmd.CreateParameter("@TICKET_NUM", adChar, adParamInput, 6, 0)
objCmd.Parameters.Append objParam
Set objParam = objCmd.CreateParameter("@VENDORID", adChar, adParamInput, 6, 0)
objCmd.Parameters.Append objParam

'Assign the values for the parameters
objCmd.Parameters("@TICKET_NUM").Value = CStr(txtTicket)
objCmd.Parameters("@VENDORID").Value = CStr(txtVendor)

'Set the recordset to the command object result
Set objRS = objCmd.Execute

by mustaqeem1

another easy way for Access Report through VB6:

Private Sub Command1_Click()
Dim ac As Access.Application
Set ac = New Access.Application
ac.OpenCurrentDatabase
ac.Visible = True
ac.DoCmd.OpenReport , acViewPreview
End Sub

This discussion is closed to new replies.