View Single Post
  #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