Results 1 to 8 of 8
  1. #1
    ttrautz is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    8

    VBA Password to Open a Form to Specific Record

    Hello,



    I have a button that opens a form, it has a password to access it. I want the form to open up to edit the current record. I keep getting an error "Run-time error '3075': Syntax error (missing operator) in query expression 'JOB NUMBER=1001'.

    Currently I am using:

    Private Sub btBILLING_Click()
    Dim strPassword As String


    strPassword = InputBox("Please enter the password: ")
    If strPassword = "PASSWORD" Then
    DoCmd.OpenForm "BILLING", , , "JOB NUMBER =" & Me!JobID
    Else
    Call MsgBox("The password you entered was incorrect")
    End If
    End Sub

    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The field name contains an inadvisable space, thus has to be bracketed.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    To add to Paul's post, it looks like the Password is a string value so your code will need to be:
    DoCmd.OpenForm "BILLING", , , "[JOB NUMBER] ='" & Me!JobID & "'"

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Password <> JobID.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Ahhh...second cup of coffee done and by Jove you are absolutely correct.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'm always correct...except when I'm wrong.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Hmm...Me too!

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    In the interest of not wasting typed characters, the variable isn't actually needed.
    Code:
    Private Sub btBILLING_Click()
    If InputBox("Please enter the password: ") = "Password" Then
      DoCmd.OpenForm "BILLING", , , "[JOB NUMBER] =" & Me.JobID
    Else
      MsgBox("The password you entered was incorrect")
    End If
    End Sub
    We all know that there is a finite number of characters left in the world, so let's start saving them, OK?

    OK, the real reason for chiming in is that lately I seem to be on a Me! kick. If your code compiles and runs now, try this:
    change Me!JobID to Me!JibID and compile again and see what happens. Then change Me!JibID to Me.JibID and try compiling again.
    If your code doesn't compile now, then don't bother - you have other problems to worry about.

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

Similar Threads

  1. Open form with specific record
    By Lukael in forum Programming
    Replies: 14
    Last Post: 11-16-2015, 06:31 AM
  2. Open form to specific record
    By zoro.1983 in forum Access
    Replies: 3
    Last Post: 05-31-2015, 11:04 AM
  3. Open form on specific record
    By iky123 in forum Forms
    Replies: 1
    Last Post: 04-11-2012, 09:56 AM
  4. Open form to specific record
    By Two Gun in forum Forms
    Replies: 7
    Last Post: 11-09-2011, 10:00 AM
  5. Open Form to Specific Record
    By batowl in forum Forms
    Replies: 1
    Last Post: 04-08-2011, 10:10 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