Solved

Problems using Select in login screen

Posted on 1998-09-25
8
169 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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 200 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

778 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