Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 12th, 2007, 10:29 AM
ppenn
Guest
 
Posts: n/a
Default 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
Else
    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

Regards
Peter
 
Old May 14th, 2007, 09:53 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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?



mmcdonal
 
Old May 14th, 2007, 10:11 AM
ppenn
Guest
 
Posts: n/a
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Invalid argument supplied for foreach() codejockey Beginning PHP 4 September 24th, 2010 03:40 AM
Invalid postback or callback argument mallikalapati ASP.NET 2.0 Professional 4 February 20th, 2008 08:38 AM
Invalid postback or callback argument everest ASP.NET 2.0 Professional 2 January 9th, 2007 08:28 AM
Invalid postback or callback argument. kingw BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 January 1st, 2007 09:49 PM
Invalid Argument.... baNTON Access VBA 4 April 27th, 2004 06:18 AM





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