Hi,

I've never really created a login screen in VB and connected it to a table in MS Access before. So I'm supposed to create a login screen and after gaining access to it, a main menu form needs to show up which would be connected to the rest of the forms.
I'm having trouble in finding the right code for the login screen but then again, I dont know what I'm exactly supposed to do. Like I wanna connect the login form using the ADODC option but i'm just really confused.

I'd appreciate it if anyone could help me out.
Thanks for your time! :)

Dani AI

Generated

Building on 's constraint to keep an ADODC/Data control and on and suggestions, a robust, assignment-friendly pattern is: keep ADODC for bound forms but perform the login check with a short ADO routine that uses parameterized SQL. That satisfies the "use ADODC" requirement while avoiding concatenated SQL, leftover open Recordsets, and common injection issues.

Add a reference to "Microsoft ActiveX Data Objects 2.x" and use an ADODB Command for the credential check. Example (VB6):

' requires reference to "Microsoft ActiveX Data Objects 2.x Library"
Private Function CheckCredentials(user As String, pass As String) As Boolean
    Dim cn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rs As ADODB.Recordset

    Set cn = New ADODB.Connection
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\users.mdb;"
    Set cmd = New ADODB.Command
    With cmd
        .ActiveConnection = cn
        .CommandText = "SELECT COUNT(*) AS C FROM LoginTable WHERE Username = ? AND Password = ?"
        .CommandType = adCmdText
        .Parameters.Append .CreateParameter("u", adVarChar, adParamInput, 50, user)
        .Parameters.Append .CreateParameter("p", adVarChar, adParamInput, 50, pass)
        Set rs = .Execute
    End With

    CheckCredentials = (rs.Fields("C").Value = 1)

    rs.Close: cn.Close
    Set rs = Nothing: Set cmd = Nothing: Set cn = Nothing
End Function

Use a Sub Main startup (as recommended) to show the login form modally and only show the main menu when frmLogin sets a public flag/property (for example Public Authenticated As Boolean) after a successful CheckCredentials. For .accdb files use the ACE provider string (Provider=Microsoft.ACE.OLEDB.12.0;...). If ADODC must be used on the login form, set its ConnectionString at runtime and use ADODC.Recordset carefully (or prefer the ADODB check above and leave ADODC for bound UI after login).

Troubleshooting & notes: set the password TextBox PasswordChar = "*", limit attempts, always close/free ADO objects, and avoid storing plain text passwords—store hashed values if possible. If provider/connection errors appear, verify the ADO reference and the correct Jet/ACE provider for the Access file type.

Recommended Answers

All 4 Replies

Are you using VB6 ?
First of all get rid of the Data control.
Never use the Data Environment.
Never use Data Controls
Don't use binding.

Add a bas file to your project, and make it the startup object (Sub Main)
Show the Login form VBModal.
The login form can have textboxes for user to enter their Name and Password, and you can check if they correctly exist in the DB.
You could have declared a public flag bLoggedIn as Boolean, and the Form can set that to True if the user succeeded.
If the user correctly enters the password, you can close the Login form, and set it to nothing (Setting to nothing should be done in that Sub Main, as the code execution will return to the line immediately after the line that showed the form VBModal.)
When code execution returns to the Sub Main, you can check that flag, and then show your other form(s).

Yes, I'm using VB6.
And I cant get rid of Data Control because my whole project works cuz of that and secondly, it's a requirement for my assignment. Um, I HAVE to connect the Login screen to the Login table in Access cuz that's an other requirement. :\

  1. accept login credential from UI.
  2. check the same in the DB. (select count(*) from user_table where user_id = "user_id" and password = "password" ). ensure user_id is unique/priamy key.
  3. if it matches (if count = 1 then)proceed further
  4. else re-prompt for credential.

^That worked. Thank you! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.