473,669 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to move to specific record in Datasheet?

I have a subform datasheet that contains a full year of records sorted by a
date field. I'm trying to programmaticall y move the record selector on the
datasheet to the first record that matches a particular date. For example,
the user clicks a button and the record selector moves to the first record
that matches today's date.

I was thinking something like this, but I'm not having any luck:

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenR ecordset("SELEC T ApptDate FROM tblAppointments
WHERE ApptDate = " & Date())
rst.MoveFirst
Me.Bookmark = rst.Bookmark
rst.Close

Is it possible to use DoCmd.GoToRecor d ? -- is it even possible to move
only the record selector in a datasheet?

thanks in advance...
Nov 12 '05 #1
5 24030
For the bookmarks to be the same between the recordsets, make a
RecordsetClone of the form's recordset. Also, where is the button located,
on the main form or the subform? Yes, DoCmd.GoToRecor d is also a
possibility.

Dim rst As DAO.Recordset
'Here is where we need to know the location of the button
'I have assumed it is on the main form
Set rst = Me.NameOfSubfor mControl.Form.R ecordsetClone
rst.FindFirst "[ApptDate]=" & Date
If rst.NoMatch Then
Msgbox "There were no records found for " & Date
Else
Me.NameOfSubfor mControl.Form.B ookmark = rst.Bookmark
End If
rst.Close
Set rst = Nothing

--
Wayne Morgan
MS Access MVP
"deko" <dj****@hotmail .com> wrote in message
news:QX******** ***********@new ssvr29.news.pro digy.com...
I have a subform datasheet that contains a full year of records sorted by a date field. I'm trying to programmaticall y move the record selector on the datasheet to the first record that matches a particular date. For example, the user clicks a button and the record selector moves to the first record
that matches today's date.

I was thinking something like this, but I'm not having any luck:

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenR ecordset("SELEC T ApptDate FROM tblAppointments WHERE ApptDate = " & Date())
rst.MoveFirst
Me.Bookmark = rst.Bookmark
rst.Close

Is it possible to use DoCmd.GoToRecor d ? -- is it even possible to move
only the record selector in a datasheet?

thanks in advance...

Nov 12 '05 #2
thanks for pointing me in the right direction - your comments are helpful
two things I've discovered:

* need to use long with FindFirst
* need to use DAO RecordsetClone with Bookmark

The problem I'm still having is how to hide the Appt_ID column in the
datasheet -- see second to last line of sub.

Private Sub Form_Open(Cance l As Integer)

'order by datasheet by date
Me.OrderBy = "[ApptDate]"
Me.OrderByOn = True

'look for an appointment in current week
'so we don't have to scroll through
'previous months of appointments
'if we can't find one,
'expand range to current month
Dim lngAidw As Long
Dim lngAidm As Long
lngAidw = Nz(DLookup("App t_ID", "qry920"), 0)
lngAidm = Nz(DLookup("App t_ID", "qry930"), 0)
MsgBox lngAidw
MsgBox lngAidm
Dim rst As DAO.Recordset
Set rst = Me.Form.Records etClone
rst.FindFirst "Appt_ID = " & lngAidw
If rst.NoMatch Then
rst.FindFirst "Appt_ID = " & lngAidm
'if still no match, go back to start
If rst.NoMatch Then
rst.MoveFirst
End If
End If
Me.Form.Bookmar k = rst.Bookmark
rst.Close

'set column widths to best fit
Dim ctl As Control
Dim strCl As String
For Each ctl In Me.Form
strCl = ctl.Name
Form(strCl).Col umnWidth = -2
Next ctl
'Form(ctl.Appt_ ID).ColumnHidde n '<=== How to hide??
DoCmd.Save acForm, "frmAllAppt s"

End Sub
Nov 12 '05 #3
> 'Form(ctl.Appt_ ID).ColumnHidde n '<=== How to hide?
Me.Appt_ID.Colu mnHidden = True

Also, the "form" in the command line was to refer to the subform from the
subform control if the button was on the main form. It appears that you are
running the code from the subform so you don't need the word form (although,
since you say it works, it doesn't appear to be hurting anything).

Example:
Me.Form.Bookmar k = rst.Bookmark
could be changed to
Me.Bookmark = rst.Bookmark

--
Wayne Morgan
Microsoft Access MVP
"deko" <dj****@hotmail .com> wrote in message
news:tr******** **********@news svr29.news.prod igy.com...
thanks for pointing me in the right direction - your comments are helpful
two things I've discovered:

* need to use long with FindFirst
* need to use DAO RecordsetClone with Bookmark

The problem I'm still having is how to hide the Appt_ID column in the
datasheet -- see second to last line of sub.

Private Sub Form_Open(Cance l As Integer)

'order by datasheet by date
Me.OrderBy = "[ApptDate]"
Me.OrderByOn = True

'look for an appointment in current week
'so we don't have to scroll through
'previous months of appointments
'if we can't find one,
'expand range to current month
Dim lngAidw As Long
Dim lngAidm As Long
lngAidw = Nz(DLookup("App t_ID", "qry920"), 0)
lngAidm = Nz(DLookup("App t_ID", "qry930"), 0)
MsgBox lngAidw
MsgBox lngAidm
Dim rst As DAO.Recordset
Set rst = Me.Form.Records etClone
rst.FindFirst "Appt_ID = " & lngAidw
If rst.NoMatch Then
rst.FindFirst "Appt_ID = " & lngAidm
'if still no match, go back to start
If rst.NoMatch Then
rst.MoveFirst
End If
End If
Me.Form.Bookmar k = rst.Bookmark
rst.Close

'set column widths to best fit
Dim ctl As Control
Dim strCl As String
For Each ctl In Me.Form
strCl = ctl.Name
Form(strCl).Col umnWidth = -2
Next ctl
'Form(ctl.Appt_ ID).ColumnHidde n '<=== How to hide??
DoCmd.Save acForm, "frmAllAppt s"

End Sub

Nov 12 '05 #4
Okay...

Dim lngAid As Long
lngAid = Nz(DLookup("App t_ID", "qry990"), 0) 'next appointment
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClo ne
rst.FindFirst "[Appt_ID] = " & lngAid
If rstNoMatch Then
rst.Close
Exit Sub
End If
Me.Form.Bookmar k = rst.Bookmark
rst.Close

Question:

There will always be only one "next appointment" -- must I use FindFirst and
NoMatch? Is there a more efficient way to say "go here or quit"?

BTW, I tried this one-liner:

DoCmd.GoToRecor d , , acGoTo, [Appt_ID] = Nz(DLookup("App t_ID", "qry990"),
First)

but GoToRecord just uses the "offset" of the current record set, which is
not much use if you don't know how many records you are going to have.

"Wayne Morgan" <co************ *************** @hotmail.com> wrote in message
news:8G******** **********@news svr32.news.prod igy.com...
'Form(ctl.Appt_ ID).ColumnHidde n '<=== How to hide? Me.Appt_ID.Colu mnHidden = True

Also, the "form" in the command line was to refer to the subform from the
subform control if the button was on the main form. It appears that you

are running the code from the subform so you don't need the word form (although, since you say it works, it doesn't appear to be hurting anything).

Example:
Me.Form.Bookmar k = rst.Bookmark
could be changed to
Me.Bookmark = rst.Bookmark

--
Wayne Morgan
Microsoft Access MVP
"deko" <dj****@hotmail .com> wrote in message
news:tr******** **********@news svr29.news.prod igy.com...
thanks for pointing me in the right direction - your comments are helpful two things I've discovered:

* need to use long with FindFirst
* need to use DAO RecordsetClone with Bookmark

The problem I'm still having is how to hide the Appt_ID column in the
datasheet -- see second to last line of sub.

Private Sub Form_Open(Cance l As Integer)

'order by datasheet by date
Me.OrderBy = "[ApptDate]"
Me.OrderByOn = True

'look for an appointment in current week
'so we don't have to scroll through
'previous months of appointments
'if we can't find one,
'expand range to current month
Dim lngAidw As Long
Dim lngAidm As Long
lngAidw = Nz(DLookup("App t_ID", "qry920"), 0)
lngAidm = Nz(DLookup("App t_ID", "qry930"), 0)
MsgBox lngAidw
MsgBox lngAidm
Dim rst As DAO.Recordset
Set rst = Me.Form.Records etClone
rst.FindFirst "Appt_ID = " & lngAidw
If rst.NoMatch Then
rst.FindFirst "Appt_ID = " & lngAidm
'if still no match, go back to start
If rst.NoMatch Then
rst.MoveFirst
End If
End If
Me.Form.Bookmar k = rst.Bookmark
rst.Close

'set column widths to best fit
Dim ctl As Control
Dim strCl As String
For Each ctl In Me.Form
strCl = ctl.Name
Form(strCl).Col umnWidth = -2
Next ctl
'Form(ctl.Appt_ ID).ColumnHidde n '<=== How to hide??
DoCmd.Save acForm, "frmAllAppt s"

End Sub


Nov 12 '05 #5
> Question:

There will always be only one "next appointment" -- must I use FindFirst and NoMatch? Is there a more efficient way to say "go here or quit"?
Not really.

In addition to the rst.Close, technically you should also Set rst=Nothing.
The general rule is that if you open it, close it. If you set it, then set
it to nothing when you're done.

--
Wayne Morgan
Microsoft Access MVP
"deko" <dj****@hotmail .com> wrote in message
news:DV******** ***********@new ssvr29.news.pro digy.com... Okay...

Dim lngAid As Long
lngAid = Nz(DLookup("App t_ID", "qry990"), 0) 'next appointment
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClo ne
rst.FindFirst "[Appt_ID] = " & lngAid
If rstNoMatch Then
rst.Close
Exit Sub
End If
Me.Form.Bookmar k = rst.Bookmark
rst.Close

Question:

There will always be only one "next appointment" -- must I use FindFirst and NoMatch? Is there a more efficient way to say "go here or quit"?

BTW, I tried this one-liner:

DoCmd.GoToRecor d , , acGoTo, [Appt_ID] = Nz(DLookup("App t_ID", "qry990"),
First)

but GoToRecord just uses the "offset" of the current record set, which is
not much use if you don't know how many records you are going to have.

Nov 12 '05 #6

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

Similar topics

3
4747
by: William Wisnieski | last post by:
Hello Everyone, Access 2000, I have a main unbound form with a bound datasheet subform . The subform is bound to a query that returns records based on criteria in the main form. The user then double clicks a row on the datasheet subform to open yet another form bound to a table . These two forms are linked by the field. So far so good.
3
7912
by: Mark | last post by:
Hi there, I have a subform, set as a continuous form. When a user selects a particular record in that subform, how can I make that particular record stand out (color or font change, size, etc) from the other records in the list? Thank you in advance, Mark
2
10039
by: Danny | last post by:
I have a checkbox that looks at the current records fields and is either checked or not based on some of these feilds. But I need to do this each time the user moves to another record, or when the cdurrent record has been changed. where would I put this code? Thanks
2
8217
by: John M | last post by:
Hi, I have a form which I would like to keep in 'FormView', but which displays rows each containing records. Generally the data will be added/updated by moving between fields, but I would also like the down arrow to move down a record and the up arrow move up a record etc. Darned if I can see how, despite searching through the help - both Access and Visual basic. Thanks in advance
5
3481
by: Bill | last post by:
This database has no forms. I am viewing an Access table in datasheet view. I'd like to execute a macro to execute a function (using "runcode"). In the function, I'll reading data from the record the cursor was on in the datasheet at the time I executed the macro. So, the questions are: 1) In the macro, how to I get my hands on the record key or record data of the record the cursor was on in the datasheet at the time I executed the...
5
3368
lwwhite
by: lwwhite | last post by:
I'm trying to reproduce functionality I've seen in some other (non-Access) applications. On one of my forms, the master record is a document. The subform consists of a datasheet list of the topics within that document--a kind of table of contents of the document. Problem is, the records in the datasheet list are not in the same order as they are in the document; rather, they're in the order that people added them to the database. I've tried...
3
1993
by: MLH | last post by:
I've pretty much always applied a filter to a form to go to a specific record - filtering out all but the desired record. Am looking for code used to move to a specific record when keyfield value is known. This would leave my form in a state that PGUP and PGDN would still navigate up 'n down the dynaset. Seeking simplest methods.
3
2231
by: Gord | last post by:
If I have a form open with a subform control on it in datasheet view that has its record source set to a query or a table, is it possible to determine which record the user has clicked into with VB? I don't mean the text box with which you can determine the field/column, but the record (row). I guess what I'm looking for would be the bookmark? (or some line numbering?) or whatever information would aid in determining unambiguously which...
2
3533
by: eko99312 | last post by:
Let's say I have this form called Attendance List. The list was in datasheet form. In the list there were names and date checklist. The question is, I want to edit one of the names by double clicking on the datasheet and it will pop up Employee Form. To pop up Employee Form by double clicking on the names are easy, but the trick is I want the Employee Form shows the specific name that I wanted (or the specific name record), normally it will open...
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8896
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8810
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8590
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6211
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2798
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.