Rst.FindFirst does not always work.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Does Rst.findFirst only look the first row/record in table?
It always return does not match.

Thanks in advance.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

How are you using it?


Hi Norie,
my current code looks like this.
I'm checking if record with current user id exist.
I do not want to loop though to check if it exist rather just quickly find it.

Thanks in advance.

Code:
[/FONT]
[FONT=Courier New]Option Compare Database
Option Explicit[/FONT]
[FONT=Courier New]Sub Test1_findFirst()
Dim rst As dao.Recordset
Dim MYXID As String[/FONT]
[FONT=Courier New]MYXID = UCase(Trim(Environ("Username")))[/FONT]
[FONT=Courier New]Debug.Print MYXID
Set rst = CurrentDb.OpenRecordset("EMPINFO", dbOpenDynaset)[/FONT]
[FONT=Courier New]rst.MoveFirst
rst.FindFirst rst!IDS = MYXID
If rst.NoMatch Then
 Debug.Print "no match"
Else
 Debug.Print "Match"
End If
rst.Close
Set rst = Nothing
End Sub
 
Upvote 0
The criteria is wrong.

I think it might be this, but I'm not sure.
Code:
rst.FindFirst "IDS = '" & MYXID & "'"
PS Why are you using rst.MoveFirst?
 
Upvote 0
The criteria is wrong.

I think it might be this, but I'm not sure.
Rich (BB code):
Rich (BB code):
rst.FindFirst "IDS = '" & MYXID & "'"

PS Why are you using rst.MoveFirst?


Norie, perfect!
Well i was just using 'rst.MoveFirst" thinking that it might be trying to find in some other records like last records etc:biggrin:

Thanks Norie
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top