Results 1 to 2 of 2
  1. #1
    topp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    12

    ComboBox checking to see if value exists

    Hello All,


    So I have created this combobox that requires the user to enter a password when selecting a value in my unbound combobox. If the password is incorrect then the combobox is cleared and is reset to the value it was before the update was attemped. Now I found code on getting this to work and it works great except for one minor flaw that I am trying to add to it. If the user goes to clear the combobox thus making the value null the Msgbox appears asking for the users password but fails each time because the null username does not exist. Im trying to make the proper if statement to check and see if the username selected from the combobox does not exist in the usertable then it just cancels the update statement.
    I tried to explain as best that I could, sorry if this sounds confusing. Here is my code for the comboBox at the moment:
    (btw I did not make this code I borrowed it from another forum)


    Code:
    Private Sub ComboAuth_AfterUpdate()
       Dim pwd As String
       Dim rs As Object, rstable As Object, count As Integer, counter As Integer
       Dim sql As String, recount As Integer
       sql = "SELECT * " & _
             "FROM [dbo_User_Table] " & _
             "WHERE [Username] = '" & Me.ComboAuth & "' "
       Set rs = CurrentDb.OpenRecordset(sql)
       recount = rs.RecordCount
       'MsgBox "Record Count" & rs.Password
       pwd = InputBox("Please enter password", "Password")
       If pwd = rs.Password Then
          rs.Close
          Set rs = Nothing
          Exit Sub   ' return control to User on the form to allow another try
       Else
          If pwd <> rs.Password Then
             ' Here if incorrect Password for this Username.
             MsgBox "That is not the correct password for" & Chr(13) & _
                    "that username. Please try Again.", vbExclamation, "Invalid Password"
             'Me.ComboAuth.
             If IsNull(ComboAuth.Text) Then
                ComboAuth.Value = ""
             Else: ComboAuth.Value = ComboAuth.OldValue
             End If
             Me.ComboAuth.SetFocus
             ' Start login process over again.
             ' Close the recordset.
             rs.Close
             Set rs = Nothing
             Exit Sub
          End If
       End If
    End Sub
    Last edited by topp; 07-10-2012 at 10:06 AM. Reason: Added code tags

  2. #2
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    After the last dim statement add the following
    Code:
    If Not isnull(ComboAuth) Then
       leave your code as it is
    End if
    End Sub
    then on the update event your existing code will execute only if theres data there. Also since I can't actually test it if the isnull doesn't work you can try several other functions such as Not (comboauth = "") or Not len(comboauth)=0 or len(comboauth) > 0 instead of the not any of these should work.

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

Similar Threads

  1. Checking beforehand whether a file exists
    By Ronald in forum Programming
    Replies: 2
    Last Post: 07-27-2011, 08:48 AM
  2. Checking if a year exists via DLookup
    By walter189 in forum Programming
    Replies: 6
    Last Post: 07-22-2011, 10:37 PM
  3. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  4. Checking if files exists
    By geoffishere in forum Access
    Replies: 1
    Last Post: 02-09-2010, 01:32 PM
  5. Replies: 0
    Last Post: 12-16-2009, 01:14 PM

Tags for this Thread

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