Solved

Problems using Select in login screen

Posted on 1998-09-25
8
167 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 3

Expert Comment

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

Use:SQLstr = "SELECT * FROM [personnel] Where username = '" & Trim$(passtext) & "';"
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

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

Accepted Solution

by:
steve06 earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the Help steve....Found some more errors and now it works fine...

Warren
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now