?
Solved

Problems using Select in login screen

Posted on 1998-09-25
8
Medium Priority
?
174 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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 In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

719 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