Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problems using Select in login screen

Posted on 1998-09-25
8
Medium Priority
?
177 Views
Last Modified: 2012-05-04
I am having a problem using the select function properly to chose a particular record from a table.  I am trying to verify that the data contained in the password field matches the txtpassword.text data.  I am getting a "runtime error 3061, too few parameters.  expected 1" message.

I also need to look at the administrator field to see if it is true and will open more options on my main page.

I am new at this and having great difficulty.  Anyone available to look at my code and offer suggestions?

Code is as follows:

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long

Dim gsDatabase As Database
Dim rs As Recordset
Dim Sqlstr As String
Dim Newrs As Recordset
Dim passtext As String

Public OK As Boolean

Private Sub Form_Load()
    Dim sBuffer As String
    Dim lSize As Long


    sBuffer = Space$(255)
    lSize = Len(sBuffer)
    Call GetUserName(sBuffer, lSize)
    If lSize > 0 Then
        txtUserName.Text = Left$(sBuffer, lSize)
    Else
        txtUserName.Text = vbNullString
    End If
End Sub





Private Sub cmdCancel_Click()
    OK = False
    Me.Hide
End Sub


Private Sub cmdOK_Click()
    passtext = txtPassword.Text
   
    Set gsDatabase = Workspaces(0).OpenDatabase("C:\Program Status Tracking Database\205 Data.mdb")
    Sqlstr = "SELECT * FROM [personnel] Where username = passtext"
    Set Newrs = gsDatabase.OpenRecordset(Sqlstr, dbOpenSnapshot)

    'now set your data control to this rs then voila! all the linked records should see only the files that they have code access to

    Set Data1.Recordset = rs
    'To Do - create test for correct password
    'check for correct password
    If Data1.Recordset.Fields("Password") = passtext Then
    'If txtPassword.Text = rs.Fields!Password.Text Then
        OK = True
        Me.Hide
    Else
        MsgBox "Invalid Password, try again!", , "Login"
        txtPassword.SetFocus
        txtPassword.SelStart = 0
        txtPassword.SelLength = Len(txtPassword.Text)
    End If
   
    If Administrator = True Then
   
    frmMain.CmdCreateGroup.Visible = True
    frmMain.CmdCreateUser.Visible = True
    frmMain.Cmdviewpersonnel.Visible = True
    Else: End If
   
End Sub

0
Comment
Question by:clarwc
8 Comments
 
LVL 1

Expert Comment

by:steve06
ID: 1436591
Clarwc,

I think the line:
    Sqlstr = "SELECT * FROM [personnel] Where username = passtext"

should be:

    Sqlstr = "SELECT * FROM [personnel] Where username = " & chr$(34) & passtext & chr$(34)

I am not sure it will solve all your problems, but it may help!

Steve.
0
 
LVL 3

Expert Comment

by:vmano
ID: 1436592
Clarwc,
can you tell me :
where is your rs recordset in your code? and
why are you assigining username field to password?

vmano

0
 

Author Comment

by:clarwc
ID: 1436593
Steve06,

I used your code and then found some of my own errors....Passtext instead of usertext etc.....

I am still having problems getting it to make visible the cmdbuttons when the administrator field is true.  It is a yes no field in the database so I am assuming that I am looking for a true false situation.  If you can help me through this last part the points are yours.  Code is now as follows:



Private Sub cmdOK_Click()
    usertext = txtUserName.Text
    passtext = txtPassword.Text
   
    Set gsDatabase = Workspaces(0).OpenDatabase("C:\Program Status Tracking Database\205 Data.mdb")
    Sqlstr = "SELECT * FROM [personnel] Where username = " & Chr$(34) & usertext & Chr$(34)
    Set Newrs = gsDatabase.OpenRecordset(Sqlstr, dbOpenSnapshot)

    Set Data1.Recordset = Newrs
    If Data1.Recordset.Fields("Password") = passtext Then
        OK = True
        Me.Hide
   
   
    Else
        MsgBox "Invalid Password, try again!", , "Login"
        txtPassword.SetFocus
        txtPassword.SelStart = 0
        txtPassword.SelLength = Len(txtPassword.Text)
    End If
     
    If frmLogin.Data1.Recordset.Fields("administrator") = True Then
   
    frmMain.CmdCreateGroup.Visible = True
    frmMain.CmdCreateUser.Visible = True
    frmMain.Cmdviewpersonnel.Visible = True
    frmMain.Label2.Visible = True
   
    Else: End If
   
   
   
End Sub


0
Independent Software Vendors: 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!

 
LVL 3

Expert Comment

by:a111a111a111
ID: 1436594
Was: Sqlstr = "SELECT * FROM [personnel] Where username = passtext"

Use:SQLstr = "SELECT * FROM [personnel] Where username = '" & Trim$(passtext) & "';"
0
 

Author Comment

by:clarwc
ID: 1436595
The password is now being checked properly.  I need to check the administrator field.
0
 
LVL 1

Accepted Solution

by:
steve06 earned 800 total points
ID: 1436596
Clarwc,

I suppose your form with login id and password is called frmLogin.

Therefore, I suggest that before hiding the form (Me.Hide), you store the value of the field administrator in a local variable in your procedure. Something like

dim blnAdmin as Boolean

.

blnAdmin = Data1.Recordset.Fields("administrator") 'be sure administrator is not created with a cap letter in your db!

Me.Unload ' This saves memory

if blnAdmin = true then
.

Steve06
0
 
LVL 2

Expert Comment

by:shogi
ID: 1436597
Just BTW, you have a same error in your

Private Sub Form_Load()
        Dim sBuffer As String
        Dim lSize As Long


        sBuffer = Space$(255)
        lSize = Len(sBuffer)

      '   Call GetUserName(sBuffer, lSize)     <====== Here the error

' You have to write, don't forget you need the new size of your string to correctly strip it.

      lSize = GetUserName sBuffer, lSize

     
        If lSize > 0 Then
            txtUserName.Text = Left$(sBuffer, lSize)
        Else
            txtUserName.Text = vbNullString
        End If
    End Sub


0
 

Author Comment

by:clarwc
ID: 1436598
Thanks for the Help steve....Found some more errors and now it works fine...

Warren
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

916 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