Results 1 to 4 of 4
  1. #1
    motogbbj is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2014
    Location
    NL-Overijssel
    Posts
    11

    .nomatch not toggling after FindFirst statement

    I try to find a record in a table (tbl_labels), when a record in the table has the same value as the textbox "ID-Code" in a form. Target is to make a toggle that turn cmdButtons on and off. The toggle does not work. Can someone help me out ? I guess the problem of not toggling the .noMatch statement, is caused by the statement FindFirst.
    ID-Code on the form is a numeric field, from table "Codes".
    "Tag" is the name of the field in the table called "tbl_labels"

    Thanks in advance for your help.

    Please find the script below:

    Private Sub Form_Current()
    Dim db As Database
    Dim rs As Recordset
    Dim Number As String
    Dim strCriteria As String
    Dim Green As Long, Cyan As Long, Red As Long, Yellow As Long, Orange As Long


    Number = 0
    Number = Me.ID_CODE
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tbl_labels", dbOpenSnapshot)

    ''RGB Color codes taken from http://gucky.uni-muenster.de/cgi-bin/rgbtab-en
    Green = RGB(0, 255, 0)
    Cyan = RGB(0, 255, 255)
    Red = RGB(255, 0, 0)
    Yellow = RGB(255, 255, 0)
    Orange = RGB(255, 165, 0)
    If Me.Label_required = True Then
    With rs
    .MoveFirst
    .FindFirst "str([tag])=' Number'"
    ''MsgBox "Record(s) to search has ID-CODE " & Number
    ''If not found, property of NoMatch is "True"
    If .NoMatch Then
    ''MsgBox ("No Records Found!")
    ''here comes action
    Me.Knop100.Enabled = False
    .MoveFirst
    Else
    ''MsgBox "Record(s) found ; ID-CODE of found label is " & Number
    ''here comes action
    Me.Knop100.Enabled = True
    End If
    End With
    End If
    Set rs = Nothing
    Set db = Nothing
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    The variable Number should not be within quote marks. Variables should never be within quotes. Anything between quotes is considered literal text.

    .FindFirst "str([tag])='" & Number & "'"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Also, Number is a Reserved Word, in Access, and these words shouldn't be used as the name for anything in this context.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    motogbbj is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2014
    Location
    NL-Overijssel
    Posts
    11

    Red face

    Quote Originally Posted by June7 View Post
    The variable Number should not be within quote marks. Variables should never be within quotes. Anything between quotes is considered literal text.

    .FindFirst "str([tag])='" & Number & "'"
    Thanks. I changed it and also replaced the variabele number with anaother name. Also converted the the form field id-code to string. See the script below. Now it is functioning properly.

    Private Sub Form_Current()
    Dim db As Database
    Dim rs As Recordset
    Dim Rownumber As String
    Dim strCriteria As String
    Dim Green As Long, Cyan As Long, Red As Long, Yellow As Long, Orange As Long
    Rownumber = 0
    Rownumber = Str(Me.ID_CODE)
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tbl_labels", dbOpenSnapshot)

    ''RGB Color codes taken from http://gucky.uni-muenster.de/cgi-bin/rgbtab-en
    Green = RGB(0, 255, 0)
    Cyan = RGB(0, 255, 255)
    Red = RGB(255, 0, 0)
    Yellow = RGB(255, 255, 0)
    Orange = RGB(255, 165, 0)
    Me.Knop100.Enabled = False
    If Me.Label_required = True Then
    With rs
    .MoveFirst
    ''WRONG STATEMENT: .FindFirst "str([tag])=' Number'"
    ''answer From accessforums.net
    .FindFirst "str([tag])='" & Rownumber & "'"
    ''MsgBox "Record(s) to search has ID-CODE " & Rownumber
    ''If not found, property of NoMatch is "True"
    If .NoMatch Then
    ''MsgBox ("No Records Found!")
    ''here comes action
    Me.Knop100.Enabled = False
    .MoveFirst
    Else
    ''MsgBox "Record(s) found ; ID-CODE of found label is " & Rownumber
    ''here comes action
    Me.Knop100.Enabled = True
    End If
    End With
    End If
    Set rs = Nothing
    Set db = Nothing
    End Sub

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

Similar Threads

  1. Replies: 2
    Last Post: 03-12-2014, 04:30 AM
  2. Toggling multiple "Yes/No" fields in a Table?
    By HvitrEbrithil in forum Access
    Replies: 8
    Last Post: 04-30-2013, 07:45 PM
  3. Replies: 1
    Last Post: 02-16-2013, 09:05 AM
  4. Using FindFirst code
    By saltydawg617 in forum Access
    Replies: 2
    Last Post: 07-29-2011, 05:21 PM
  5. Replies: 21
    Last Post: 12-27-2009, 09:19 PM

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