p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access VBA (http://p2p.wrox.com/forumdisplay.php?f=80)
-   -   Invalid Argument (http://p2p.wrox.com/showthread.php?t=57801)

ppenn May 12th, 2007 10:29 AM

Invalid Argument
Hi I have a table with users name who are permitted to se certain parts of a form. On the form I have a function that obtains the username and asigns it to a text box.

What I want to do is when the form opens is run a query that checks the table to see if the user is listed if he is then enable certain buttons on the form. If he is not there then disable the buttons.
The code I have attempted is as follows:

Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strResult, strUser
Dim sSQL As String
Const cQUOTE = """"

txtUser = OSUserName

Set db = CurrentDb()
sSQL = "SELECT tblAdminUsers.Username FROM tblAdminUsers WHERE tblAdminUsers.Username=" & cQUOTE & Me![txtUser] & cQUOTE

Set rs = db.OpenRecordset(sSQL, dbOpenDynaset)

strResult = rs

If Me.txtUser = strResult Then
    Me.cmdUsers.Visible = True
    Me.cmdUsers.Visible = False
End If

I have tried several variations on this without success, I keep getting the following error:

Runtime error 3001 Invalid argument

Any help would be gratefully received


mmcdonal May 14th, 2007 09:53 AM

An easier way to do this is to get the user information at start up and post it to a form, and then hide the form (acHidden) when you open it. Put the user's access level in this form too. I use a Group like Administrator, User, etc.

Then on the on format event of the form's detail section, or on the on load event of the form, check the value in the text box on the hidden form, and set the buttons etc to visible based on the user.

Then no queries needed, which are problematic with data latency issues anyway.

Did that help any?


ppenn May 14th, 2007 10:11 AM

Thanks very much for your reply - sounds good to me - I will give it a try and let you know
Thanks again

All times are GMT -4. The time now is 12:43 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.