General discussion

Locked

Access reports through VB6

By matthewdeas ·
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

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Miss Kitty In reply to Access reports through VB ...

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

Collapse -

Access Report from VB6

by mustaqeem In reply to Access reports through VB ...

another easy way for Access Report through VB6:

Private Sub Command1_Click()
Dim ac As Access.Application
Set ac = New Access.Application
ac.OpenCurrentDatabase <DataBaseName with Path>
ac.Visible = True
ac.DoCmd.OpenReport <ReportName>, acViewPreview
End Sub

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums