Compile Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Benjamin Moses
    New Member
    • Dec 2018
    • 1

    Compile Error

    It highlight "Password second line " compile error. Method o data member not found.
    Code:
    Private Sub Command10_Click()
        If Me.Password = DLookup("password", "users", "username = '" & Me.UserName & "'") Then
            Me.ID DLookup("id", "users", "username = '" & Me.UserName & "'")
            DoCmd.OpenForm "main"
            Me.Visible = False
        Else
            MsgBox "access denied"
        End If
    End Sub
    Last edited by NeoPa; Dec 14 '18, 12:23 AM. Reason: Added mandatory [CODE] tags and formatted so it was at least almost readable.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32634

    #2
    Originally posted by Benjamin Moses
    Benjamin Moses:
    It highlight "Password second line " compile error.
    Excuse me for asking but what are you even talking about?

    That text that you have in the quotes doesn't appear anywhere in your code. How do you expect anyone to answer a question that doesn't make sense? Why did you post this without checking it at least made sense?

    So, I can't answer your question, but I can warn you against the idea of managing security credentials within your database. Particularly in plain text as you seem to be attempting.

    Maybe this has been a blessing in disguise as it gives us the opportunity to warn you about how very bad and dangerous an idea it is even to attempt such an approach.

    On the other hand, as a general rule, and when the question makes any sort of sense, we'll be happy to help you with your code. Compile errors are generally pretty straightforward .

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32634

      #3
      As it happens it may be that we can find your compile problem in spite of your inability to direct us where to look.

      Line #3 in your code can never work as it simply lists two values. It looks like an assignment is required so it would need an "=" after Me.ID.

      I can't stress enough though, that even thinking of doing things this way is not something any experienced developer would ever do. It's just such a bad idea.

      Comment

      • cameronhunter
        New Member
        • Dec 2018
        • 7

        #4
        You're getting the error because
        Code:
        showInputsDialog
        isn't a member of the form, it's a member of the module you're calling it from. You should also be getting compiler errors on these two lines...

        Code:
        Call Initialize
        Me.Show
        ...because you seem to be getting the module and form code mixed up.

        That said, you're overthinking this. A UserForm is a class module, and it can be stored in a variable (or in this case, in a With block), and can have properties. I'd add a Cancelled property to the form:

        Code:
        'In sportsUsrFrm
        Option Explicit
        
        Private mCancel As Boolean
        
        Public Property Get Cancelled() As Boolean
            Cancelled = mCancel
        End Property
        
        Private Sub cmdCnl_Click()
            Me.Hide
            mCancel = True
        End Sub
        
        Private Sub cmdOK_Click()
            If Valid Then Me.Hide   '<-- You still need to implement `Valid`
        End Sub
        And then call it like this:

        Code:
        Sub sportUserForm()
            With New sportsUsrFrm
                .Show
                Dim sSport As String, sPreference As String
                If Not .Cancelled Then
                    If .optBaseball.Value Then
                        sSport = "Baseball"
                    ElseIf .optBasketball.Value Then
                        sSport = "Basketball"
                    Else
                        sSport = "Football"
                    End If
        
                    If .optTV.Value Then
                        sPreference = "watch on TV"
                    Else
                        sPreference = "go to games"
                    End If
                    MsgBox "Your favorite sport is " & sSport & ", and you usually " _
                           & sPreference & "."
                Else
                    MsgBox "Sorry you don't want to play."
                End If
            End With
        End Sub

        Comment

        • twinnyfo
          Recognized Expert Moderator Specialist
          • Nov 2011
          • 3653

          #5
          Cameronhunter,

          Did you respond to the wrong thread?

          Comment

          Working...