Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method 'Open' of object '_Recordset' failed 1

Status
Not open for further replies.

JoPaBC

Technical User
Sep 26, 2017
85
0
0
CA
Hello,

I am adding one procedure populating a Datagrid into existing project; hereis the new, added code giving me an error message as above.

Code:
Private Sub Command14_Click()
    Dim rst4 As ADODB.Recordset
    Dim sSQL4 As String
    
    If Combo1.Text = "Select Pay Period" Then
        MsgBox "Select Pay Period!"
        Exit Sub
    End If

    DataGrid4.ClearFields

    sSQL4 = "SELECT [FULL_NAME], [WDATE], [WTYPE], [WHRS], [PCODE], [WRATE] FROM NAMES, WHOURS, PAYPER WHERE [NAMES].[EMPID]=[WHOURS].[EMPID] AND [PAYPER].[PAYPER]='" & Combo1.Text & "' AND [WHOURS].[PAYPER]=[PAYPER].[PPID];"
    Debug.Print sSQL4
    Set rst4 = New ADODB.Recordset
    rst4.Open sSQL4, objAccessConnection, adOpenKeyset, adLockOptimistic

    Set DataGrid4.DataSource = rst4

    With DataGrid4
        .Columns(0).Width = 2800
        .Columns(1).Width = 1500
        .Columns(2).Width = 1500
        .Columns(3).Width = 500
        .Columns(4).Width = 500
        .Columns(5).Width = 500

    End With
    
End Sub

Debug.print of the sSQL4:
SQL:
SELECT [FULL_NAME], [WDATE], [WTYPE], [WHRS], [PCODE], [WRATE] FROM NAMES, WHOURS, PAYPER WHERE [NAMES].[EMPID]=[WHOURS].[EMPID] AND [PAYPER].[PAYPER]='FEB 01-15' AND [WHOURS].[PAYPER]=[PAYPER].[PPID];


Result if I run the sql directly in my MS Access database:
Code:
FULL_NAME	WDATE	WTYPE	WHRS	PCODE	WRATE
FOERTER, MYLES	2/05/19	R/T	7	55	16
FOERTER, MYLES	2/06/19	R/T	7	55	16
FOERTER, MYLES	2/07/19	R/T	7.5	55	16
FOERTER, MYLES	2/12/19	R/T	7.25	55	16
FOERTER, MYLES	2/14/19	R/T	8	55	16

Any idea please how to fix it?
Thanks!
 
Any idea? Yes, indeed:
What is "objAccessConnection"? Where is it defined, initialised, opened? What is its state when you execute this code?

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Your problem is

[tt]FROM NAMES[/tt]

Change to

[tt]FROM [NAMES][/tt]

as Names is a reserved word in SQL-92, and thus in Jet 4.0
 
Thank you, strongm! Yes, that was the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top