473,382 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

findfirst use

Hi everyone,

I'm using findfirst in code as below. It searches a query that shows
appointment date and account name and should return the account name of
the first appointment on each day into the same date in a calendar
form.

If rs.RecordCount 0 Then
For i = 1 To 37
If IsDate(f("date" & i)) Then
myDate = Format((f("date" & i)), "mm/dd/yyyy")
rs.FindFirst ("appdate = #" & myDate & "#")
If rs.NoMatch Then
f("text" & i).BackColor = 10944511
Else:
f("text" & i) = rs!ACCOUNTNAME
f("text" & i).BackColor = 12058551

However if I have 2 appointments on the same date it is returning the
last appointment in the query from that date. Why? From being new to
this I presumed findfirst would find the first in the list!

I am trying to get the code to return all of the appointments on each
day. I tried altering the code to this;

If rs.RecordCount 0 Then
For i = 1 To 37
If IsDate(f("date" & i)) Then
myDate = Format((f("date" & i)), "mm/dd/yyyy")
rs.FindFirst ("appdate = #" & myDate & "#")
If rs.NoMatch Then
f("text" & i).BackColor = 10944511
Else:
rs.FindNext ("appdate = #" & myDate & "#")
If Not rs.NoMatch Then
f("text" & i) = rs!ACCOUNTNAME
f("text" & i).BackColor = 12058551

Which then returns the first record on a date.

How do I get it to return both records, not one or the other?
(I am learning by trial and error and my knowledge of code is still
tiny so simple explanations would be appreciated!)

Thanks everyone.

Dec 9 '06 #1
2 2427
suggest you add an OrderBy clause to your query, so that the records are
returned in the order that you need. then add the following code to the
procedure, *before* the "If rs.RecordCount 0 Then " line, as

rs.MoveLast
rs.MoveFirst

to ensure that all the records are loaded to the recordset, and then the
FindFirst action begins at the "top" of the records.

hth
"keri" <ke*********@diageo.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
Hi everyone,

I'm using findfirst in code as below. It searches a query that shows
appointment date and account name and should return the account name of
the first appointment on each day into the same date in a calendar
form.

If rs.RecordCount 0 Then
For i = 1 To 37
If IsDate(f("date" & i)) Then
myDate = Format((f("date" & i)), "mm/dd/yyyy")
rs.FindFirst ("appdate = #" & myDate & "#")
If rs.NoMatch Then
f("text" & i).BackColor = 10944511
Else:
f("text" & i) = rs!ACCOUNTNAME
f("text" & i).BackColor = 12058551

However if I have 2 appointments on the same date it is returning the
last appointment in the query from that date. Why? From being new to
this I presumed findfirst would find the first in the list!

I am trying to get the code to return all of the appointments on each
day. I tried altering the code to this;

If rs.RecordCount 0 Then
For i = 1 To 37
If IsDate(f("date" & i)) Then
myDate = Format((f("date" & i)), "mm/dd/yyyy")
rs.FindFirst ("appdate = #" & myDate & "#")
If rs.NoMatch Then
f("text" & i).BackColor = 10944511
Else:
rs.FindNext ("appdate = #" & myDate & "#")
If Not rs.NoMatch Then
f("text" & i) = rs!ACCOUNTNAME
f("text" & i).BackColor = 12058551

Which then returns the first record on a date.

How do I get it to return both records, not one or the other?
(I am learning by trial and error and my knowledge of code is still
tiny so simple explanations would be appreciated!)

Thanks everyone.

Dec 9 '06 #2
I already have an order by in the code, (this is above the code posted
earlier). I have tried changing the order by to another field eg.
app_time, but I get an error of too few parameters.
sql = "SELECT * FROM [querycalendar] WHERE ((MONTH(appdate) = " &
f!month & " AND YEAR(appdate)= " & f!year & ")) ORDER BY appdate;"

Set db = CurrentDb()
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)

Dec 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul | last post by:
The 2 statements below work perfectly when using them individually. But when I try to concatenate them, they don't. rst.FindFirst " = " & OldQuoteNumber rst.FindFirst " Is Null" Can someone...
1
by: cnlai | last post by:
Snippets -------- Dim mydb As Database, myset As DAO.Recordset Set mydb = CurrentDb Set myset = mydb.OpenRecordset("abc") myset.FindFirst (" = 'S02'") '<< problem here Reference: MS DAO...
5
by: MLH | last post by:
I have a table I can open as table type recordset or a dynaset. Searching for a particular value in the table's main keyfield, which would be faster and less strain on the application......
2
by: rivka.howley | last post by:
I wrote some code that creates a table with a date/time field at 15-minute intervals. Here's how I create and populate the table With tblDataTemp ..Fields.Append .CreateField("CT_ID", dbLong)...
6
by: Shyguy | last post by:
Is there a way to use this when entries have an apostrphe in them? Like Joe's Bar and Grill.
7
by: waltvw | last post by:
I'm using FindFirst method in Access VBA to find a particular record in a recordset. I have 2 search criteria each of which works just fine if used separately as an argument in FindFirst, but NOT in...
3
by: boliches | last post by:
I am trying to get a continuous form to highlight lines individually (ideally on hover). I have used the following code as recommended by a previous entry on this website. My problems begin in that...
2
by: Denise | last post by:
Front end is Access 2002, back end is linked Oracle tables. My users need to describe things in feet and inches and want to use the standard ' and " abbrevations. On a testing form I go to a...
25
by: Rick Collard | last post by:
Using DAO 3.6 on an Access 2002 database, I'm getting unexpected results with the FindFirst method. Here's the simple code to test: Public Sub FindIt() Dim db As Database, rs As Recordset...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.