Link to home
Start Free TrialLog in
Avatar of bastille2
bastille2

asked on

Stupid little VBA error

Hi,

I know MS Access pretty well, but I'm not very skilled with VBA.  I'm trying to code something anyway.  I want this function attached to the BeforeOpen event of the Employees form so when I try to open it, I get sent to the Reports form.

I get the error "object required"  at the line that starts "If BobName="
What stupid thing am I doing wrong?

********************
Option Compare Database

Public Function Out()

Dim dbCurr As Database
Dim BobName As String

Set dbCurr = DBEngine.Workspaces(0).Databases(0)
Set BobName = Environ(UserName)

    If BobName = "robert.smith" Then
        DoCmd.OpenForm "Reports Form", acNormal
    End If

End Function
Avatar of Tommy Kinard
Tommy Kinard
Flag of United States of America image

Public Function Out()

Dim dbCurr As Database
Dim BobName As String

Set dbCurr = DBEngine.Workspaces(0).Databases(0)
BobName = Environ(UserName)    '<-here

    If BobName = "robert.smith" Then
        DoCmd.OpenForm "Reports Form", acNormal
    End If

End Function

HTH
dragontooth

Don't feel to bad I did the same thing :)

Public Function Out()

    Dim dbCurr As Database
    Dim BobName As String
   
    Set dbCurr = DBEngine.Workspaces(0).Databases(0)
    BobName = Environ$("UserName")    '<-here
   
    If BobName = "robert.smith" Then
        DoCmd.OpenForm "Reports Form", acNormal
    End If

End Function

HTH
dragontooth

Avatar of bastille2
bastille2

ASKER

Hey! that fixed it.  Thanks.  Might I impose on you for one more thing?  It opens the Reports form nicely, but it does so in addition to the Employees form.  I want it to open reports instead of employees.  How would I abort the event that opens Employees?
Where are you opening the Employees form at? I would start there. If to no avail, in the Employees inialize event check the forms collection to see if the Report form is loaded and kill the employee load, in other words the employee to unload itself if the reports is loaded.

Another way:
If BobName = "robert.smith" Then
        DoCmd.OpenForm "Reports Form", acNormal
else
        DoCmd.OpenForm "Employee Form", acNormal
End If

Let me know
dragontooth

On the switchboard is a button that normally opens the Employees form.  It has an on click event =HandleButtonClick(1), I added my function in the OnEnter event.  The point of this is that when someone clicks on the button to open the Employees form, I want my little function to check if it's robert.smith, and if it is, send him to the reports form insted.  I want to keep him out of the Employees form without having to implement User Level Security.
ASKER CERTIFIED SOLUTION
Avatar of Tommy Kinard
Tommy Kinard
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
dragontooth,

Thanks, I think that'll do it.

Bob
Thanks!
Let me know if I can help more. :)

dragontooth