473,399 Members | 2,858 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,399 software developers and data experts.

Goto a specific record is a form

112 100+
I have a button on a popup form that when clicked runs a code to duplicate the current record that I am viewing on my main form. It first asks me to enter a new number (primary key) into a pop-up box and then duplicates the record replacing the primary key with the new number. I use this in cases where the next record only requires a few field changes, so I don’t have to retype the hold record. The problem is that when the code runs to do this, it ends by filtering to the duplicated record. I would like it to go to that record without filtering out all the other records. That way I can move back a couple of records if I need to without un-filtering and then re-finding that record. The code at the end that filters to the new record is:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmDescription", acNormal, , "[Accession Number]='" + MyValue + "'"
MyValue is the new record number.
I did not write this code and I do not understand code very well but am slowly learning.
I think that I need to replace it with a Findfirst code but am not sure?
I have been working with this code but have had no luck…

Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acForm, "frmDescription"
  2. DoCmd.OpenForm "frmDescription"
  3.  
  4. Dim rst As Recordset
  5.             Dim strSearchName As String
  6.             Set rst = Me.RecordsetClone
  7.             strSearchName = Str([Accession Number] = MyValue)
  8.             rst.FindFirst "Accession Number = " & strSearchName
  9.                      Me.Bookmark = rst.Bookmark
Can anyone one help?
Mar 3 '11 #1
8 8177
patjones
931 Expert 512MB
Hi Redbeard,

Is MyValue a number or a string?

Pat
Mar 3 '11 #2
Redbeard
112 100+
It is a string

Expand|Select|Wrap|Line Numbers
  1. Dim MyValue As String 
'represents the new accession number
Mar 3 '11 #3
patjones
931 Expert 512MB
When you do a comparison for string values, you need to enclose the target value in quotes. I would eliminate line 7, and write line 8 like this:

Expand|Select|Wrap|Line Numbers
  1. rst.FindFirst "[Accession Number] = '" & MyValue & "'"

Try it and let us know how it works (or doesn't, as the case may be).

Pat
Mar 3 '11 #4
Redbeard
112 100+
Still an error… Run Time Error 246: The expression you entered refers to an object that is closed or does not exist.
When I go to debug it highlights this line:
Expand|Select|Wrap|Line Numbers
  1. Set rst = Me.RecordsetClone
Mar 3 '11 #5
patjones
931 Expert 512MB
What form did you drop this code into? The "Me." formalism will only work if the code is in the module for the form that you want to populate.

Pat
Mar 3 '11 #6
Redbeard
112 100+
Thanks Pat! The "Me." was my problem, I changed it to
Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2.             Set rst = Forms!frmDescription.RecordsetClone
  3.             rst.FindFirst "[Accession Number] = '" & MyValue & "'"
  4.  
  5.                 Forms!frmDescription.Bookmark = rst.Bookmark
It now runs Perfectly!

Thanks!
Mar 3 '11 #7
patjones
931 Expert 512MB
That's no problem. Let me know if there are any other issues.
Mar 3 '11 #8
NeoPa
32,556 Expert Mod 16PB
For something pretty similar I use a technique whereby I simply extend the existing filter to include the newly added record. I include an example to illustrate. In the example [ClipboardID] is the PK of the table being maintained (in this case a numeric value) :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterInsert()
  2.     Me.Filter = Me.Filter & " OR ([ClipboardID]=" & lngID & ")"
  3. End Sub
Mar 4 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Simone | last post by:
Hello!!! Here is the thing. I have had this problem and I want to address it now where in the next and previous button DoCmd.GoToRecord , , acNext - DoCmd.GoToRecord , , acPrevious I wish the...
2
by: RC | last post by:
I would like to go to a specific record based on what the user types in a text box on a form. I have a table named: Boxes in the table there is a field named: BoxNumber a form named: BxForm ...
1
by: Ian | last post by:
I want to open a form at a particular record, but I think I'm running into problems because the recordsource query is executing asynchronously. In the form's open event I use...
10
by: ApexData | last post by:
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...
2
by: nkoske | last post by:
I have a form with a subform in datasheet view and I have a event on one of the fields in the subform, so that the user can double click it and go to expanded information based on that field. ...
2
by: Timbo | last post by:
Hi there, I’m not used to working in VB and I think this situation calls for excactly that. I use Access 97 SR-2. My first table is a table containing all the Tickets I got. The field ”Ticket”...
2
by: Jpipher | last post by:
Let me explain what I am trying to accomplish... Two forms -- we'll call them "Main" and "Related" A command button on "Main" runs a union query. The union query results are shown in "Related"...
3
by: eighthman11 | last post by:
Using Access 2000. I have a continuous form which for simplicity sack has two fields Social Security Number and Last Name. In the header of the continuous form I have a textbox where you can...
3
by: DavidB | last post by:
I want to be able to go to a specific record on my form when I open it. The record I want to go to will be dynamic based on the value currently stored in a global variable. The global contains...
1
by: cvillav | last post by:
Hello, I am new to Access and this forums, I have two tables and two forms to display the data. Tables Tbuilding Tcriteria Forms fmbuilding
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: 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
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...
0
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...
0
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,...
0
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...
0
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...
0
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,...

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.