Results 1 to 9 of 9
  1. #1
    nahum abramovich is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jun 2018
    Posts
    62

    error while writing code for entering form

    hi

    need your help please

    i am trying to create a password for entering my form.

    what i did:

    i open the form in design view - EVENT - ON OPEN -... i wrote this code (bellow):

    Dim password As String
    password = InputBox("and the password is.....")
    If password = "1Q1Q" Then


    MsgBox "Welcome Engineer"
    Else
    MsgBox "check the CapsLK my friend..."
    DoCmd.Close
    End If


    than when i closed the form and try to enter the form this error appear:

    The expression On Open you entered as the event property setting produced the following error: a problem occurred while microsoft access was communicating with the OLE server or Activex control

    This error occurs when an event has failed to run because the location of the logic for the event cannot be evaluated. For example, if the OnOpen property of a form is set to =[Field], this error occurs because a macro or event name is expected to run when the event occurs.

    thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Instead of DoCmd.Close just Cancel = True

    However, Access is not case sensitive by default. This means "1q1q" will equal "1Q1Q".

    Use StrComp() function.

    If StrComp("1Q1Q", password, vbBinaryCompare) = 0 Then

    Might find this recent thread of interest https://www.accessforums.net/showthread.php?t=80854
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    nahum abramovich is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jun 2018
    Posts
    62
    hi
    I'm not sure I understood you, but it seem that i tried all the possibilities...
    i change the password and i tried all this (bellow) - with no success


    Private Sub Form_Open(Cancel As Integer)
    Dim password As String
    password = InputBox("and the password is.....")
    If StrComp("123", password, vbBinaryCompare) = 0 Then
    MsgBox "Welcome Engineer"
    Else
    MsgBox "try again"
    DoCmd.Close
    End If
    End Sub



    Private Sub Form_Open(Cancel As Integer)
    Dim password As String
    password = InputBox("and the password is.....")
    If StrComp("123", password, vbBinaryCompare) = 0 Then
    MsgBox "Welcome Engineer"
    Else
    MsgBox "try again"
    Cancel = True
    End If
    End Sub


    Private Sub Form_Open(Cancel As Integer)
    Dim password As String
    password = InputBox("and the password is.....")
    If password = "123" Then
    MsgBox "Welcome Engineer"
    Else
    MsgBox "try again"
    Cancel = True
    End If
    End Sub

    Private Sub Form_Open(Cancel As Integer)
    Dim password As String
    password = InputBox("and the password is.....")
    If password = "123" Then
    MsgBox "Welcome Engineer"
    Else
    MsgBox "try again"
    DoCmd.Close
    End If
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    What does "no success" mean - error message, wrong result, nothing happens?

    I tested code and second example works for me.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    I think this is VBA code corruption behind the form. Here's what 'sometimes' has worked for me.
    In the VBA editor, select all the code for the form and Cut it. CTRL-A to select, CTRL-X to cut.
    Save , Debug > compile.
    Compact/Repair.
    Open the DB and view the form in design mode.
    In the code module behind the form, Paste the code back in.
    Save, debug > compile.

  6. #6
    nahum abramovich is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jun 2018
    Posts
    62
    You're right The 2nd code works. But something strange is happening.
    The code only worked when i operate it on a new, blank form that I created.( form no 1)
    When I run the code on my existing form (external doc- it the name of my form) it does not work and shows me the error.
    ( in addition - my existing form have only 4 buttons that do nothing and one buttons that close the form - that is all)



    So I tried the next thing - from design view i copied all the 5 buttons from external doc to the blank form -form no 1 and still i ave the same error

  7. #7
    nahum abramovich is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jun 2018
    Posts
    62
    hi davegri

    i tried it also - no success

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    As already suggested, provide db for analysis.

    So something about buttons ...

    Create new buttons one at a time (test code between each) on new form.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    nahum abramovich is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jun 2018
    Posts
    62
    Hi
    I can't send the file at this time.


    I know this is not the usual way but I managed to work it out indirectly so that it was enough for me. I created an intermediate form between the first form and the other forms.
    so now the code works on the blank form and from the blank form I can open all the forms that follow.

    for me its ok...

    I thank you and everyone for the help. Not obvious.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code writing
    By Obidombie in forum Forms
    Replies: 1
    Last Post: 02-11-2016, 04:11 AM
  2. Replies: 7
    Last Post: 06-13-2014, 10:41 AM
  3. Replies: 1
    Last Post: 06-15-2011, 03:29 PM
  4. Replies: 2
    Last Post: 03-29-2011, 01:26 PM
  5. Replies: 0
    Last Post: 03-15-2010, 02:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums