Dear members.
I am using a MS Access 2013 DB & the Login Form contains the following VBA code:
Option Compare Database
Option Explicit
Private Sub btnLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tblUser", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "txtUserName ='" & Me.UserName & "'"
If IsNull([UserName]) Then
MsgBox "You must enter an User Name"
Me.UserName.SetFocus
Exit Sub
End If
If IsNull([Passwrd]) Then
MsgBox "You must enter Pass Word"
Me.Passwrd.SetFocus
Exit Sub
End If
If rs.NoMatch = True Then
Me.lblWrongUser.Visible = True
Me.UserName.SetFocus
Exit Sub
End If
Me.lblWrongUser.Visible = False
If rs!txtUserPassword <> Me.Passwrd Then
Me.lblWrongPass.Visible = True
Me.Passwrd.SetFocus
Exit Sub
End If
Me.lblWrongPass.Visible = False
TempVars("UserType") = rs!UserType_ID.Value
If rs!UserType_ID = 2 Then
Dim prop As Property
On Error GoTo SetProperty
Const DB_Boolean As Long = 1
Set prop = CurrentDb.CreateProperty("AllowBypasskey", DB_Boolean, False)
CurrentDb.Properties.Append prop
SetProperty:
If MsgBox("Would you like to turn on the bypass key?", vbYesNo, "Allow Bypass") = vbYes Then
CurrentDb.Properties("AllowBypassKey") = True
Else
CurrentDb.Properties("AllowBypassKey") = False
End If
End If
DoCmd.Close acForm, "frmLogon", acSaveNo
Dim intStore As Integer
intStore = Nz(DCount("[Factory_ID]", "[InsurancePositionQry]"), 0)
If intStore = 0 Then
DoCmd.OpenForm "Switchboard"
ElseIf intStore = 1 Then
If MsgBox("For one Factory, insured value is less than stock value." & _
vbCrLf & vbCrLf & "Would you like to see the details and analyze the reason now?", _
vbYesNo + vbCritical, "CAUTION....FACTORY SHORT OF INSURANCE...") = vbYes Then
DoCmd.OpenForm "InsurancePositionForm", acNormal
Else
DoCmd.OpenForm "Switchboard"
End If
Else
If MsgBox("For " & intStore & " Factories, insured value is less than stock value." & _
vbCrLf & vbCrLf & "Would you like to see the details and analyze the reason now?", _
vbYesNo + vbCritical, "CAUTION....FACTORIES SHORT OF INSURANCE...") = vbYes Then
DoCmd.OpenForm "InsurancePositionForm", acNormal
Else
DoCmd.OpenForm "Switchboard"
End If
End If
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.UserName.SetFocus
End Sub
The above code I got from Steve Bishop's Access 2013 YouTube lessons and working fine for the past about 2 years. Last Week I was creating an new data entry form & after that on Login the following message popped up:
Run-time error '3367' :
Cannot append. An object with the name asready exists in the
collection.
On debugging the error shows in the following line:
CurrentDb.Properties.Append prop
Even after removing the newly created form, the same message pops up. However I removed the particular code line & it works fine. I request the experts to please analyze the reason & also advise if it is advisable to permanently remove that line.
Regards
Alex