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).Dat abases(0)
Set BobName = Environ(UserName)
If BobName = "robert.smith" Then
DoCmd.OpenForm "Reports Form", acNormal
End If
End Function
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).Dat
Set BobName = Environ(UserName)
If BobName = "robert.smith" Then
DoCmd.OpenForm "Reports Form", acNormal
End If
End Function
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).Dat abases(0)
BobName = Environ$("UserName") '<-here
If BobName = "robert.smith" Then
DoCmd.OpenForm "Reports Form", acNormal
End If
End Function
HTH
dragontooth
Public Function Out()
Dim dbCurr As Database
Dim BobName As String
Set dbCurr = DBEngine.Workspaces(0).Dat
BobName = Environ$("UserName") '<-here
If BobName = "robert.smith" Then
DoCmd.OpenForm "Reports Form", acNormal
End If
End Function
HTH
dragontooth
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
Another way:
If BobName = "robert.smith" Then
DoCmd.OpenForm "Reports Form", acNormal
else
DoCmd.OpenForm "Employee Form", acNormal
End If
Let me know
dragontooth
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
dragontooth,
Thanks, I think that'll do it.
Bob
Thanks, I think that'll do it.
Bob
Thanks!
Let me know if I can help more. :)
dragontooth
Let me know if I can help more. :)
dragontooth
Dim dbCurr As Database
Dim BobName As String
Set dbCurr = DBEngine.Workspaces(0).Dat
BobName = Environ(UserName) '<-here
If BobName = "robert.smith" Then
DoCmd.OpenForm "Reports Form", acNormal
End If
End Function
HTH
dragontooth