confusion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rudeman76
    New Member
    • Oct 2007
    • 58

    confusion

    Hello again, I have a textbox on a form where the user enters in a unique tag number. I have it set up in the table that it has to be a unique number, but this shows them the error once the record is complete. What i am trying to do is error check it one the user enters it in. I have two screens that will use this code. I have it working on one form, but for some reason it will not work on the other (code is pretty much identical). this is the code that works. The only difference between this and the one that does not work is the table name (tblPSA) and feild names (tagno). The one that does not work gives me the msgbox all the time.

    Code:
    Private Sub Tag_No_Lostfocus()
            Dim rst As Object
        Dim db As Object
        Dim intmsg As Integer
    
     'checking if tag already exists
        Set db = CurrentDb
        Set rst = db.openrecordset("bags recieved")
        If blnTest = False Then
            If rst.RecordCount <> 0 Then
                rst.MoveFirst
                Do While Not rst.EOF
            
                    If rst("tag no").Value = Me.Tag_No.Value Then
                        intmsg = MsgBox("That tag has already been used, you cannot add the tag again.", vbOKOnly, "Tag Error")
                    
                        blnTest = True
                    End If
          
                    rst.MoveNext
                Loop
            End If
        End If
        rst.Close
        Set rst = Nothing
        Tag_No.DefaultValue = Me.Tag_No.Value + 1
    End Sub
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It hasn't given you any errors at all?
    Have you tried stepping through the code?

    I would double check all field names, table names, control names etc. I would also check to make sure the data types are the same.

    Also, why are you dimming them as objects instead of recordset/database?
    As far as I'm aware, there is no .Value property for recordset fields.

    Comment

    • rudeman76
      New Member
      • Oct 2007
      • 58

      #3
      I have stepped through it and it is working fine, it just reads the last record as well, which is the one i am comparing the rest to. I got it to work by starting at the last record and working backwards. The reason I am dimming them as objects is that when was dimming them as recordsets, it would not let me edit the record (I am not sure why) I could addnew, but not edit. As soon as i dimmed them objects and did it this way, it worked. I have used the .value in the rest of my db and its worked so far.

      Andrew

      Comment

      Working...