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

need help with gotorecord

Below is my code. What I want do is ,after running the insert
statement into tblarchive, I want to go to the subform and set focus to
the record that I just added in
Confirm = "'" + CONF + "'"
usr = "'" + CurrentUser() + "'"
strSQL = "INSERT INTO tblarchive ( conf, csrID, csdate, comments )
SELECT " & Confirm & " AS Expr1, " & usr & " AS Expr2, Date() AS
Expr3, 'cxl' AS Expr4;"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL (running the insert sql statement)
DoCmd.SetWarnings True
DoCmd.Close acForm, "cancel", acSaveYes
Forms![MAIN-members]![Child135].SetFocus (set focus to the
subform)
Forms![MAIN-members]![Child135]!comments.SetFocus
DoCmd.GoToRecord (need help here go to the record that just ran
above)

thank

Apr 12 '06 #1
3 3077
You might be able to Requery the subform, and then go to the last record.
But if the table does not have an AutoNumber, or if the AutoNumber is not
sequential, or if other users are adding records, this might not take you to
to desired one.

Would you consider an AddNew on the RecordsetClone of the subform instead of
running the update query? That avoids the Requery, and you know for certain
that you are ending up with the correct record.

This kind of thing (assuming the code goes in the main form's module):
Dim rs As DAO.Recordset
With Me.Child135.Form
Set rs = .RecordsetClone
rs.AddNew
rs!conf = Confirm
rs!csrID = use
rs!csdate = Date()
rs!comments = "cxl"
rs.Update
.Bookmark = rs.LastModified
End With
Set rs = Nothing

The alternative would be to Execute the query statement instead of RunSQL,
and ask Access for the new identity value, requery the subform, and then
FindFirst in its RecordsetClone. That's a long way round for a shortcut, and
works in JET 4 only (Access 2000 and later.)

--
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.

<co*****@yahoo.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
Below is my code. What I want do is ,after running the insert
statement into tblarchive, I want to go to the subform and set focus to
the record that I just added in
Confirm = "'" + CONF + "'"
usr = "'" + CurrentUser() + "'"
strSQL = "INSERT INTO tblarchive ( conf, csrID, csdate, comments )
SELECT " & Confirm & " AS Expr1, " & usr & " AS Expr2, Date() AS
Expr3, 'cxl' AS Expr4;"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL (running the insert sql statement)
DoCmd.SetWarnings True
DoCmd.Close acForm, "cancel", acSaveYes
Forms![MAIN-members]![Child135].SetFocus (set focus to the
subform)
Forms![MAIN-members]![Child135]!comments.SetFocus
DoCmd.GoToRecord (need help here go to the record that just ran
above)

Apr 12 '06 #2
Thank you for the code but it's keep on jumping back the first record
on the subform
child135. it does not stay at the record that it just modified.

just curious if I set
Set rst = CurrentDb.OpenRecordset("tblarchive", dbOpenDynaset)
this should works as well. is there a preference of RecordsetClone
over
OpenRecordset?

Dim rst As DAO.Recordset
Dim strSQL, Confirm, usr As String

Confirm = CONF
usr = CurrentUser()
DoCmd.Close acForm, "cancel", acSaveYes

Forms![MAIN-members]![Child135].SetFocus
Forms![MAIN-members]![Child135]!comments.SetFocus

With Forms![MAIN-members].Child135.Form
Set rst = .RecordsetClone
rst.AddNew
rst!CONF = Confirm
rst!csrID = usr
rst!csdate = DATE
rst!comments = "cxl"
rst.Update
.Bookmark = rst.LastModified
End With
Set rst = Nothing

Apr 12 '06 #3
Jumping back to the first record after setting the form bookmark is not the
normal behavior, so something else must be going on as well.

It could be a Requery, or it might be related to something that happens in
the main form. Access reloads the subform when the main form moves record
(or is requeried.)

If you OpenRecordset on the table and add the record there, the new record
will not be in the form's recordset until a requery. You will then need to
FindFirst in the RecrodsetClone of the of the form, i.e. you cannot match
the Bookmark of the table's recordset against that of the form.

--
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.

<co*****@yahoo.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
Thank you for the code but it's keep on jumping back the first record
on the subform
child135. it does not stay at the record that it just modified.

just curious if I set
Set rst = CurrentDb.OpenRecordset("tblarchive", dbOpenDynaset)
this should works as well. is there a preference of RecordsetClone
over
OpenRecordset?

Dim rst As DAO.Recordset
Dim strSQL, Confirm, usr As String

Confirm = CONF
usr = CurrentUser()
DoCmd.Close acForm, "cancel", acSaveYes

Forms![MAIN-members]![Child135].SetFocus
Forms![MAIN-members]![Child135]!comments.SetFocus

With Forms![MAIN-members].Child135.Form
Set rst = .RecordsetClone
rst.AddNew
rst!CONF = Confirm
rst!csrID = usr
rst!csdate = DATE
rst!comments = "cxl"
rst.Update
.Bookmark = rst.LastModified
End With
Set rst = Nothing

Apr 13 '06 #4

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

Similar topics

3
by: Eric | last post by:
What's the best way to cancel the new record when doCmd.GoToRecord , , acNewRec is executed and before the new record is actually written to the database. I'm maintaining an existing Access 97...
6
by: Michael Goerz | last post by:
Hi, I'm trying to write a loop that cycles through all the records. This I use for doing comparisons between all records or to export all records to a text file. I'm using the following code: ...
1
by: STeve Lefevre | last post by:
Hey folks -- I'm using the DoCmd.GoToRecord , , acNext to jump to the next record after the user enters a value. The problem is, it throws an error if it's already on the last record! What's the...
0
by: Timppa | last post by:
Hi, I'm converting ACCESS 2000 database to SQL Server. I have .adp project. In the .mdb I have form where I'll insert rows into two different tables using docmd.GoToRecod ,,acNewRec. In .adp...
2
by: longtim | last post by:
I have been trying to implement navigation buttons for a number of forms in my application. Creating the 'Next' 'Previous' buttons has been fine but setting the enabled properties doesn't work...
15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
4
by: MLH | last post by:
Access 97 has left examples out of much of HELP that was included in Access 2.0. Anybody know why? Or better still, where to find examples. For example, Access 97 has no example code in its...
2
by: vostrixos | last post by:
Hi I can't make a code work.What i do is that i'm creating a fileDialog object and later in the same function i use a Docmd.GoToRecord.I've notice that after i use the '.show' property within the...
7
by: MLH | last post by:
If I'm using the following in a procedure... DoCmd.GoToRecord acDataForm, "FormName", acNext, 4 .... how can I recognize the EOF condition? Using GoToRecord, I find myself lost when trying to...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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,...

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.