473,699 Members | 2,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GOTO Indexed Record in Code

Hello

How do I goto a specific record in a BOUND form when the form has a
primary
index of ID which is autonumbered. I need to visit 4 seperate records,
one at a time.

This works for RecNO but no good for Field search: DoCmd.GoToRecor d ,
, acGoTo, 19
And I know is NOT recommended.

I Also tried SQL in code, but keep getting syntax errors:
strSQL = "Select * From "T-Table" Where ID = 20"
Set Rst = CurrentDb.OpenR ecordset(strSQL , dbSnapshotOnly)

Please Help

May 13 '06 #1
10 5024
Use FindFirst on the RecordsetClone of the form.

Example:

If Me.Dirty Then 'Save first.
Me.Dirty = False
End If
With Me.RecordsetClo ne
.FindFirst "ID = 20"
If .NoMatch Then
MsgBox "not found"
Else
Me.Bookmark = .Bookmark
End If
End With

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<Ap******@gmail .com> wrote in message
news:11******** **************@ d71g2000cwd.goo glegroups.com.. .
Hello

How do I goto a specific record in a BOUND form when the form has a
primary
index of ID which is autonumbered. I need to visit 4 seperate records,
one at a time.

This works for RecNO but no good for Field search: DoCmd.GoToRecor d ,
, acGoTo, 19
And I know is NOT recommended.

I Also tried SQL in code, but keep getting syntax errors:
strSQL = "Select * From "T-Table" Where ID = 20"
Set Rst = CurrentDb.OpenR ecordset(strSQL , dbSnapshotOnly)

May 14 '06 #2
"Ap******@gmail .com" <Ap******@gmail .com> wrote in
news:11******** **************@ d71g2000cwd.goo glegroups.com:
Hello

How do I goto a specific record in a BOUND form when the form
has a primary
index of ID which is autonumbered. I need to visit 4 seperate
records, one at a time.

This works for RecNO but no good for Field search:
DoCmd.GoToRecor d , , acGoTo, 19
And I know is NOT recommended.

I Also tried SQL in code, but keep getting syntax errors:
strSQL = "Select * From "T-Table" Where ID = 20"
Set Rst = CurrentDb.OpenR ecordset(strSQL , dbSnapshotOnly)

Please Help

you can use

rst.findfirst "fieldname = " & criteria
if not rst. nomatch then .
...... whatever.
That works on everything, and may use indexes, even though the
help says it doesn't.

You can try the .seek method, check the help for that, but it
only works with .openrecordset( sql,dbOpenTable )

iirc dbSnapshotOnly should be dbOpenSnapshot, which might
explain your error messages.

--
Bob Quintal

PA is y I've altered my email address.
May 14 '06 #3
ThankYou for the responses.

I tried the FindFirst method that Allen suggested, and it works fine.
But, having read some posts over the last 2-hours, am concerned that it
is "Obsolete" and slow and may cause me problems when I split the DB
and run it over the network. Those posts mention Seek and SQL as the
prefered methods, however, I cannot seem to get the SQL in code to
work.

AnyThoughts?

May 14 '06 #4
FINALLY

I finally managed to get SQL to work at finding each specific record I
was looking for.
The code below does it. Is this method advisable? Will it satisfy the
concerns of my previous post?

Private Sub DBTEST()
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
strSQL = "SELECT * FROM [T-Table] Where ID = 20" 'Id is indexed
autonumber
Set db = CurrentDb
Set rs = db.OpenRecordse t(strSQL, dbOpenForwardOn ly)
MsgBox rs!MyField
strSQL = "SELECT * FROM [T-Table] Where ID = 19"
Set rs = db.OpenRecordse t(strSQL, dbOpenForwardOn ly)
MsgBox rs!MyField
End Sub

May 14 '06 #5
"Ap******@gmail .com" <Ap******@gmail .com> wrote in
news:11******** **************@ y43g2000cwc.goo glegroups.com:
ThankYou for the responses.

I tried the FindFirst method that Allen suggested, and it
works fine. But, having read some posts over the last 2-hours,
am concerned that it is "Obsolete" and slow and may cause me
problems when I split the DB and run it over the network.
Larry is "obsolete". The .seek method is faster, when it works.
But it often doesn't work. And if you split the database, and move
the back end into SQL server, the seek method definitely will not
work reliably.
Those posts mention Seek and SQL as the prefered methods,
however, I cannot seem to get the SQL in code to work.

AnyThoughts?


Glad you got it to work (I saw your other post)

--
Bob Quintal

PA is y I've altered my email address.
May 14 '06 #6
SQL is a good idea in most cases. You've used it to find a record and
determine the value of "MyField". How will you use that information to
move the record pointer on the bound form?
Usually we use a Bookmark for that as Allen and Bob have suggested. Can
you get a meaningful bookmark from your SQL?
If not, perhaps you should reconsider and use their ideas. Could
FindFirst be very slow? Perhaps, if the Form has a HUGE recordset, it
could be. But if that's the case then there may be other problems too.
Seek is unlikely to be significantly faster than SQL execution (some
SQL might be written a bit more efficiently than yours). As Bob has
pointed out, Seek works on TableType Recordsets only. You have to open
linked tables directly to use Seek.
Why mess with this and open a recordset of many records and then Seek
one, when you can just as efficiently use SQL to open a recordset of
just that one record (as you have done)? I used to be a great champion
of Seek. I haven't even considered using it for years.
I suggest you follow Allen's suggestion which is very clear and see how
it works. If it's too slow then repost with that new speed problem.

May 14 '06 #7
"Ap******@gmail .com" <Ap******@gmail .com> wrote in
news:11******** **************@ y43g2000cwc.goo glegroups.com:
I tried the FindFirst method that Allen suggested, and it works
fine. But, having read some posts over the last 2-hours, am
concerned that it is "Obsolete" and slow and may cause me problems
when I split the DB and run it over the network. Those posts
mention Seek and SQL as the prefered methods, however, I cannot
seem to get the SQL in code to work.


It depends on what you're attempting to do.

If you're moving the current record in a set of records in a form,
then Allen's method (with .FindFirst on the RecordsetClone) is the
best.

If you're trying to open a recordset with a selected set of records
then SQL is the right way to go.

SEEK plays no role in either of those scenarios, and is not really
going to be useful in very many situations, as it's limited to
table-type recordsets and to a single table. And it's useful only in
the situations where you need to open a large table and jump around
that table extensively.

Finally, in cases where you need to jump around a non-table-type
recordset, FindFirst/FindNext/FindPrevious operations can be
optimized if your recordset is sorted in the order of the field
you're matching on. In that case, you'd cache the value of the last
find operation and decide whether to use FindNext or FindPrevious,
only using FindFirst on the initial find. The result of that
optimization is that you end up moving the minimum distance through
the searched column.

It's still not as efficient as SEEK, but when SEEK is not an option,
it's a great improvement over multiple FindFirst operations.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
May 14 '06 #8
>SQL is a good idea in most cases. You've used it to find a record and
determine the value of "MyField". How will you use that information to
move the record pointer on the bound form?


I'm happy with the SQL, however I need to BookMark 1-Record and I can't
seem to
make it happen. I want to use Allen & Bob's suggestions (ie FindFirst)
since it
works ideally for my situation and the speed is not an issue. If I go
this route will the operation be reliable on the NETWORK and will the
FindFirst statement likely remain
compatible with future environments?

ThankYou ALL
Greg

May 14 '06 #9
"Ap******@gmail .com" <Ap******@gmail .com> wrote in
news:11******** **************@ i39g2000cwa.goo glegroups.com:
SQL is a good idea in most cases. You've used it to find a
record and determine the value of "MyField". How will you use
that information to move the record pointer on the bound form?


I'm happy with the SQL, however I need to BookMark 1-Record
and I can't seem to
make it happen. I want to use Allen & Bob's suggestions (ie
FindFirst) since it
works ideally for my situation and the speed is not an issue.
If I go this route will the operation be reliable on the
NETWORK and will the FindFirst statement likely remain
compatible with future environments?

ThankYou ALL
Greg

I use .findFirst/last/next/previous across the network all the
time, with data stored in SQL Server, other Access .mdbs, and
occasionally linked Excel spreadsheets.
--
Bob Quintal

PA is y I've altered my email address.
May 14 '06 #10

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

Similar topics

4
2591
by: dixie | last post by:
I have a table called "tblParticipants" with a field called "ID", which must be indexed with No duplicates allowed. I am looking for a way of doing in vba a small if ..then ..else .. routine that looks at that field in that table and if it is not indexed, indexes it, and if it is indexed, jumps to a label. I have a query called "qryAddIndex" that will index the field, what I really need is the vba to test if the field is indexed or not. ...
7
2254
by: RC | last post by:
When I am adding records to a database and each record is unique by the Serial Number. I would like to step through my code adding records unless the Serial Number already exists in the database. If the record already exits, then I would like to pop up a form, in pop-up, dialog mode. The form will ask if the user wants to make changes to the existing record and go back to the form and not make any changes. The code stops because the...
37
3245
by: Tim Marshall | last post by:
From http://www.mvps.org/access/tencommandments.htm 9th item: Thou shalt not use "SendKeys", "Smart Codes" or "GoTo" (unless the GoTo be part of an OnError process) for these will lead you from the path of righteousness. What about also using it as a means of exiting a procedure?
34
26635
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
1
3714
by: ing42 | last post by:
I have a problem with inserting records into table when an indexed view is based on it. Table has text field (without it there is no problem, but I need it). Here is a sample code: USE test GO CREATE TABLE dbo.aTable ( INT NOT NULL
1
1189
by: mover9000 | last post by:
I am relatively new with PHP and have a problem using the SELECT function. While accessing a 66,000 record database, I am attempting to read CITY, STATE, AND ZIP. The file has as one of its indexes CITY STATE ZIP. However, I have noticed that the read is very slow when there are many identical CITY STATE with various zipcodes, and rapid when only a few. How could this be? An indexed search should immediately retrieve the correct CITY STATE...
1
1489
by: Pacific Fox | last post by:
Hi all, I am dealing with a very large database, and as soon as a record is submitted I need to run a full-text query against it. I believe it might take a while before the record is fully indexed and therefore would not return a result. How can I check whether the record in question is already indexed, if at all?
5
1371
by: jON Rowlan | last post by:
I am slowing get my head around the concept of treating tables as collections of rows as vb.net seems to prefer. However, I have an indexed table in an Access database that I want to scan. I want to match a certain field but don't want to issue one select statement for each row in my master table. I'd rather connect the table to an object and then use a seek or locate command to get to the correct row that I want.
25
3914
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 Dim sCriteria As String Set db = DBEngine.Workspaces(0).Databases(0) Set rs = db.OpenRecordset("tblTest", dbOpenDynaset)
0
8687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9034
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...
0
7750
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
6534
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
5874
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();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3057
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
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.