troubleshooting Question

Access 2010 VBA to put one field from a query in a variable

Avatar of UbiqutyDegins
UbiqutyDegins asked on
Microsoft ApplicationsMicrosoft Access
7 Comments1 Solution530 ViewsLast Modified:
In Access 2010 I need to be able to click a command button that will run a query that returns a small two field recordset. Then put the second field in that recordset into a string variable.

This string variable is a link to a word document on the network. the second part of the code will then open the word document.(This part I have working)

I am getting the error Too few parameters. Expected 1.Error Message
Any help is GREATLY appreciated

Private Sub cmdCESpec_Click()

On Error GoTo Err_cmdCESpec_Click
Dim db As Database
Dim rs As Recordset
Dim s As String
Dim specSheet As String

s = "SELECT tblParts.PartNum, tblParts.CE_SpecSheet FROM tblParts WHERE (((tblParts.PartNum)=[Forms]![frmSpecSheet]![cboPartNum]));" 'Chooses the Correct Spec Sheet
Set db = CurrentDb
Set rs = db.OpenRecordset(s)

specSheet = rs.Fields("CE_SpecSheet")  'Chooses the Spec Sheet Field


    Dim oApp As Object
    Set oApp = CreateObject("Word.Application")
    oApp.Visible = True
    With oApp
        .Documents.Open ("specSheet")
    End With
    Exit Sub

    MsgBox Err.Description
    Resume Exit_cmdCESpec_Click
End Sub

Open in new window

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros