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
bastille2Asked:
Who is Participating?
 
Tommy KinardConnect With a Mentor Commented:
In the on click event take out the empolyee form load and put this function in it's place. Can you post the code for the on click event?

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
    else
        DoCmd.OpenForm "Employee Form", acNormal
    End If

End Function

dragontooth

0
 
Tommy KinardCommented:
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

0
 
Tommy KinardCommented:
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

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
bastille2Author Commented:
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?
0
 
Tommy KinardCommented:
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

0
 
bastille2Author Commented:
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.
0
 
bastille2Author Commented:
dragontooth,

Thanks, I think that'll do it.

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

dragontooth

0
All Courses

From novice to tech pro — start learning today.