?
Solved

Stupid little VBA error

Posted on 2005-04-01
8
Medium Priority
?
399 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:bastille2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 13684379
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
 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 13684409
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
 

Author Comment

by:bastille2
ID: 13684501
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 13684570
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
 

Author Comment

by:bastille2
ID: 13684716
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
 
LVL 14

Accepted Solution

by:
Tommy Kinard earned 960 total points
ID: 13684861
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
 

Author Comment

by:bastille2
ID: 13708992
dragontooth,

Thanks, I think that'll do it.

Bob
0
 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 13709528
Thanks!
Let me know if I can help more. :)

dragontooth

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question