User Login

Robby19

Board Regular
Joined
Mar 19, 2018
Messages
227
I broke my new user login form. I removed the uLogonCount from the tblUsers and from the below strSQL code and now whenever the New User form comes up I get the following error;

Number of query values and destination fields are not the same.

I also added a few columns to the tblUser table. So maybe that is why, but I don't think so.

Code:
Option Compare Database
Option Explicit
Private Sub cmdContinue_Click()
 On Error GoTo ErrHandler
      Dim strSQL As String
      If Nz(Me.txtFirstName, "") = "" Then
       MsgBox ("First Name cannot be empty.")
       DoCmd.GoToControl "txtFirstName"
      Exit Sub
      End If
      If Nz(Me.txtLastName, "") = "" Then
       MsgBox ("Last Name cannot be empty.")
       DoCmd.GoToControl "txtLastName"
      Exit Sub
      End If
      If Nz(Me.txteMail, "") = "" Then
       MsgBox ("Email cannot be empty.")
       DoCmd.GoToControl "txteMail"
      Exit Sub
      End If
      DoCmd.SetWarnings False
      strSQL = "INSERT INTO tblUsers ( uNetworkID, uFirstName, uLastName, ueMail, uLastLogon, uSecurityID, uActive )" & _
      "  Values ('" & Environ("UserName") & "'  , '" & Me.txtFirstName & "', '" & Me.txtLastName & "', '" & Me.txteMail & "', Now(), 1, 9, True )"
      DoCmd.RunSQL strSQL
       Forms("frmPrivAct").Tag = "Continue"
      DoCmd.Close acForm, Me.Name
Complete:
  Exit Sub
ErrHandler:
   MsgBox ("Error creating user profile: " & Err.Description)
 End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
      strSQL = "INSERT INTO tblUsers ([COLOR=#0000ff] uNetworkID[/COLOR], [COLOR=#0000ff]uFirstName[/COLOR], [COLOR=#0000ff]uLastName[/COLOR], [COLOR=#0000ff]ueMail[/COLOR], [COLOR=#0000ff]uLastLogon[/COLOR], [COLOR=#0000ff]uSecurityID[/COLOR], [COLOR=#0000ff]uActive [/COLOR])" & _
      "  Values ('" & [COLOR=#008000]Environ("UserName") [/COLOR]& "'  , '" & [COLOR=#008000]Me.txtFirstName [/COLOR]& "', '" & [COLOR=#008000]Me.txtLastName [/COLOR]& "', '" & [COLOR=#008000]Me.txteMail[/COLOR] & "', [COLOR=#008000]Now()[/COLOR], [COLOR=#008000]1[/COLOR], [COLOR=#008000]9[/COLOR], [COLOR=#008000]True [/COLOR])"

You have 7 fields but 8 values... remove either '1,' or '9,' depending on which one IS NOT the SecurityID.

Also - why save the security ID at all if it is a hardcoded value? seems superfluous.
 
Last edited:
Upvote 0
Thank you!

The SecurityID is assigned based off the New User form and a Module. It can then be changed by someone with a higher assigned security code.
 
Upvote 0
Stumac is saying that your insert statement has 7 field but 8 values which is a no-can-do:

Insert into Table (F1, F2, F3, F4, F5, F6, F7) values (1,2,3,4,5,6,7,8) ==> FAIL
Insert into Table (F1, F2, F3, F4, F5, F6, F7) values (1,2,3,4,5,6,7) ==> OKAY
 
Upvote 0

Forum statistics

Threads
1,213,521
Messages
6,114,104
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top