Solved

Problems using Select in login screen

Posted on 1998-09-25
8
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

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!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

623 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