Solved

DoCmd.GoToRecord SYNTAX

Posted on 2014-11-17
4
441 Views
Last Modified: 2014-12-05
Hello ~ I'm attempting to go to a specific record on an open form using:
DoCmd.GoToRecord acDataForm, "frmProject", , "projID =" & ProjLINK

I receive: Run-time error 2498
ProjLINK is an integer
projID  is an auto-number ID and the primary key reflected on frmProject

Clearly I'm missing something here.
Would appreciate illumination!

Many Thanks!
0
Comment
Question by:Chi Is Current
4 Comments
 
LVL 75
ID: 40449142
You might try this:

docmd.GoToRecord acDataForm, "frmProject",acGoTo, "[projID] =" & CLng(me![ProjLINK])


Where is ProjLINK located ?  A field or text box on the Form ?
mx
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40449483
GoToRecord is just for moving up/down the records.

For searching use:

DoCmd.SearchForRecord, "frmProject", acFirst, "projID = " & ProjLINK & ""

/gustav
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 40455772
In Access 2003, there is no SearchForRecord, there is DoCmd.FindRecord
With many records, that becomes BRUTALLY slow.

These days, I'd use
Dim db As Database
Dim rst As DAO.Recordset
Dim strCriteria As String
Dim TheprojID as Long
strCriteria = "projID = " & ProjLINK
    
'finding no match takes forever so
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT projID from WhatEverTable where " & strCriteria & ";", dbOpenDynaset, dbSeeChanges)
If rst.RecordCount = 0 Then
    response = MsgBox("No such projID found.", vbInformation)
Else
    TheprojID = rst!projID
    rst.Close
    strCriteria = "projID  = " & TheJobID
    Set rst = Me.RecordsetClone
    rst.MoveLast
    rst.FindLast strCriteria
    Me.Bookmark = rst.Bookmark
End If

Set rst = Nothing

Open in new window


It performs an order of magnitude faster than DoCmd.FindRecord once you start going north of 10K records
0
 
LVL 2

Author Comment

by:Chi Is Current
ID: 40484320
Hello mx, /gustav & Nick67, thank you ALL for your thoughtful replies.
I am most grateful for your ideas and expertise.

Seems this is not really as much of a syntax question as a strategy question.

I think the best way of displaying the desired record is by using Nick67's method:
    ...
    rst.FindLast strCriteria
    Me.Bookmark = rst.Bookmark

Gotta give Nick67 the points for pure psychic accuracy,
this solution is perfect.

Thank you ~ Jacob
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question