Access VBA Form - Find if Record Exists

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • risk32
    New Member
    • Mar 2008
    • 98

    Access VBA Form - Find if Record Exists

    I'm trying to do something that I'm not exactly sure how to go about. I know about queries and how to do those, but my form isn't set up for that particular purpose. Like a webpage that has a "Check Username Available" type of function for some, that's exactly what I want to do. All my form consists of right now is a text box, txtUsername, and a command button. My table is named Members with a record column named Username. Any help with this is appreciated.
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Checkout the DLOOKUP() function. It will allow you to extract e.g. the password for the value entered in the txtUsername field.

    Nic;o)

    Comment

    • risk32
      New Member
      • Mar 2008
      • 98

      #3
      Nico,
      I'm not exactly trying to extract a password so to speak. Basically, I just need to write an If statement to see if the value entered in txtUsername is in the column Username. It could just be that I need to develop a string search and search the records for that particular string.

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Something like this:
        Code:
        Private Sub SearchUserNames_Click()
         If Not IsNull(Me.txtUserName) Then
          If DCount("UserName", "NameTable", "[UserName] = '" & Me.txtUserName & "'") > 0 Then
            MsgBox "User Name Found!"
          Else
            MsgBox "User Name Not Found!"
          End If
         End If
        End Sub
        Linq ;0)>

        Comment

        • risk32
          New Member
          • Mar 2008
          • 98

          #5
          Thanks Linq,
          This worked perfectly. All I had to do was tweak it slightly. I appreciate all you guys do for us, especially those still learning.

          Adam

          Comment

          Working...