Link to home
Start Free TrialLog in
Avatar of T B
T BFlag for Saudi Arabia

asked on

ms access convert macro to vba

Dear Expert,

My combo box in a form having macro to run after update (i.e. after selecting the value) and it was running perfectly. Unfortunately, while converting some other code from  macro to vba this macro also was converted to vba. to which after converting this combo box after update is generating an error (TempVars can only store data. They cannot store object).

Could you please help to make this code

The code in vba as follow:

Private Sub cboReports_AfterUpdate()
On Error GoTo cboReports_AfterUpdate_Err

    ' _AXL:<?xml version="1.0" encoding="UTF-16" standalone="no"?>
    ' <UserInterfaceMacro For="cmdEmployeeList" Event="OnClick" xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application" xmlns:a="http://schemas.microsoft.com/office/accessser
    ' _AXL:vices/2009/11/forms"><Statements><Action Name="OpenForm"><Argument Name="FormName">frm01_Project List</Argument><Argument Name="View">Datasheet</Argument></Action></Statements></UserInterfaceMacro>
    If (IsNull(Screen.ActiveControl)) Then
        Exit Sub
    End If
    TempVars.Add "ReportToOpen", Screen.ActiveControl
    If (CurrentProject.IsTrusted) Then
        Screen.ActiveControl = Null
    End If
    DoCmd.OpenReport TempVars!ReportToOpen, acViewPreview, "", "", acNormal
    TempVars.Remove "ReportToOpen"


cboReports_AfterUpdate_Exit:
    Exit Sub

cboReports_AfterUpdate_Err:
    MsgBox Error$
    Resume cboReports_AfterUpdate_Exit

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of T B

ASKER

Issue solved.

Change line from
 tempvars.Add "ReportToOpen", Screen.ActiveControl

Open in new window


to

tempvars.Add "ReportToOpen", (Screen.ActiveControl)

Open in new window


Thanks,
Avatar of T B

ASKER

Dear MacroShadow.

I've seen your method much more straight forward, hence it's implemented.

Thanks for your reply and help.