Hello,
I have researched this for hours and cannot find a solution. In Excel VBA, I am trying to populate a text box in a userform in Access which is used when running a make table query. My code works great the first time I run it, but returns Error 462 if run
again without closing the Excel worksheet. Can someone please help me with this code so I can move on with my life? I appreciate any help I can get.
Public Sub GetPlansQuery(planidtorun As String)
Dim appAccess As Object
Dim strDatabasePath As String
strDatabasePath = USERS_ACCESSDATABASEFILEPATH & USERS_ACCESSDATABASE
On Error GoTo ErrHandler:
Set appAccess = CreateObject("Access.Application")
With appAccess
appAccess.OpenCurrentDatabase (strDatabasePath)
appAccess.DoCmd.SetWarnings False
appAccess.DoCmd.OpenForm ("Form1")
[Forms]![Form1]![Text0].Text = planidtorun 'THIS IS WHERE THE CODE RETURNS THE ERROR
appAccess.DoCmd.OpenQuery "Aqry_1a2_GetPlans"
appAccess.DoCmd.Close acForm, ("Form1"), acSaveNo
appAccess.DoCmd.SetWarnings True
End With
My_Exit:
On Error Resume Next
If Not appAccess Is Nothing Then
appAccess.CloseCurrentDatabase
appAccess.Quit
End If
Exit Sub
'
ErrHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume My_Exit:
End Sub