Share via

Can't FindFirst

Anonymous
2024-09-06T18:03:16+00:00

In the OnCurrent event of a form, I have the following code:

If Me!RemBox = "REM" Then

    Dim rst As DAO.Recordset, WOValue As Variant

    Dim lngBlue As Long, lngGreen As Long, lngRed As Long, lngYellow As Long, lngWhite As Long

    lngRed = RGB(255, 0, 0)

    lngYellow = RGB(255, 255, 0)

    lngBlue = RGB(173, 216, 230)

    lngGreen = RGB(144, 238, 144)

    lngWhite = RGB(255, 255, 255)

    WOValue = Me!WONo.Value

 MsgBox "[WONo]=" & WOValue

    Set rst = CurrentDb().OpenRecordset("SCHEDULE")

rst.FindFirst "[WONo]=" & WOValue

    Do While "[WONo]=” & WOValue

        If Not rst.NoMatch Then

           Forms!ScheduleForm!SONo.BackColor = lngYellow

        End If

        rst.FindNext "[WONo]=" & WOValue

    Loop

End If

The line rst.FindFirst “[WONo]=” & WOValue always errors ‘Operation is not supported for this type of object’. WONo is a field on the form and in the underlying table. It is ShortText and it is indexed. The MsgBox line gives a correct display [WONo]=112233

What am I doing wrong?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

11 answers

Sort by: Most helpful
  1. Anonymous
    2024-09-07T16:18:34+00:00

    Finally got it to find the record with: rst.FindFirst "[WONo]='" & WOValue & "'"

    Now I have a statement: Forms!ScheduleForm!SONo.BackColor = lngYellow

    where lngYellow is dim as Long

    and its value is lngYellow = RGB(255, 255, 0)

    However, the field SONo is NOT showing up as yellow or any other color.

    How do you set a datasheet field on a split form to have a BackColor in VBA??

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2024-09-07T15:37:19+00:00

    Still getting the same error message.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2024-09-07T15:37:08+00:00

    Still getting the same error message.

    Was this answer helpful?

    0 comments No comments
  4. ScottGem 68,830 Reputation points Volunteer Moderator
    2024-09-07T11:05:51+00:00

    Try DIMming WOValue as String

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2024-09-07T10:15:17+00:00

    Change the line

    Set rst = CurrentDb().OpenRecordset("SCHEDULE")

    to

    Set rst = CurrentDb.OpenRecordset("SCHEDULE", dbOpenDynaset)

    Was this answer helpful?

    0 comments No comments