Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
Old May 14th, 2007, 09:53 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 07:38 AM
Invalid postback or callback argument everest ASP.NET 2.0 Professional 2 January 9th, 2007 07:28 AM
Invalid postback or callback argument. kingw BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 January 1st, 2007 08:49 PM
Invalid Argument.... baNTON Access VBA 4 April 27th, 2004 06:18 AM



All times are GMT -4. The time now is 12:59 PM.


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