Check for New Record?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am trying to use a single form for both viewing old records and adding new
ones. I have one command button on the main form that opens my form and goes
to a new record using:

DoCmd.OpenForm stDocName
DoCmd.GoToRecord acDataForm, stDocName, acNewRec

and another button on the main form that opens the form and goes to a
specific record using:

DoCmd.OpenForm stDocName

and then in the OnLoad area of the form it finds a specific record using:

Set rs = Me.Recordset.Clone
rs.FindFirst stlinkcriteria
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

My problem is that I only want this code in the OnLoad area (along with some
other coding) to run if I click the second button. I don't want to run the
code if it is simply going to a new record. Is there some way to check if the
DoCmd.OpenForm command that is run used the acNewRec option or not? Or
perhaps I am going about this in the wrong way. I checked the
me.form.newrecord, but either way it came back with a 0. Any help would be
greatly appreciated...
 
Hi, Russ.
My problem is that I only want this code in the OnLoad area (along with some
other coding) to run if I click the second button.

Use the other form's OpenArgs Property when opening it. In the first
button's code, try:

DoCmd.OpenForm stDocName, , , , , , "New"
DoCmd.GoToRecord acDataForm, stDocName, acNewRec

In the OnLoad( ) event of the other form, try:

If (Me.OpenArgs <> "New") Then
Set rs = Me.Recordset.Clone
rs.FindFirst stlinkcriteria
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

.. . . followed by the rest of your code.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Thanx Gunny - Can you put anything in the OpenArgs area? I've never used that
before...
 
Yes you can put just about anything into a text string that passes an on open
arg.

I would also suggest that you try using the this in your On Load event:

If not Me.NewRecord then
Set rs = Me.Recordset.Clone
rs.FindFirst stlinkcriteria
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
end if


Hope this helps....

Russ said:
Thanx Gunny - Can you put anything in the OpenArgs area? I've never used that
before...
Hi, Russ.
[quoted text clipped - 59 lines]
 
Hi, Russ.

You're welcome. The OpenArgs Property must be a string value. If there's
more than one value to pass, then the values can be concatenated, but with a
delimiter, such as a semicolon, between each value. The form being opened
can parse out the parts of the string and use them as needed. For example:

DoCmd.OpenForm stDocName, , , , , , "New York;32;#4/1/2005#"

This passes a string, a number, and a date within the OpenArgs string. The
non-string values within this string would need to be converted to their
actual data types in a VBA procedure in the form to be opened, but that's
pretty straightforward. So, even though it must be a string, this
requirement is easy to work around.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.
 
The code within this IF block will never execute if placed in the OnLoad( )
event of a form. It will always be false, no matter whether it's a new
record, the first record, or some other specific record in the record set
that the form is supposed to open to. The Form's NewRecord Property won't
be decernable until the OnCurrent( ) event, which occurs after the OnLoad( )
event where Russ wants to run his code.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.


Boyd "Hi Tech Coach" via AccessMonster.com said:
Yes you can put just about anything into a text string that passes an on
open
arg.

I would also suggest that you try using the this in your On Load event:

If not Me.NewRecord then
Set rs = Me.Recordset.Clone
rs.FindFirst stlinkcriteria
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
end if


Hope this helps....

Russ said:
Thanx Gunny - Can you put anything in the OpenArgs area? I've never used
that
before...
Hi, Russ.
[quoted text clipped - 59 lines]
me.form.newrecord, but either way it came back with a 0. Any help
would be
greatly appreciated...
 
Oops. I wrote the exact opposite of what I meant. It should read:

"The code within this IF block will always execute if placed in the
OnLoad( ) event of a form."

It will never be a new record when checked in the OnLoad( ) event. Sorry
for any confusion.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.


'69 Camaro said:
The code within this IF block will never execute if placed in the
OnLoad( ) event of a form. It will always be false, no matter whether
it's a new record, the first record, or some other specific record in the
record set that the form is supposed to open to. The Form's NewRecord
Property won't be decernable until the OnCurrent( ) event, which occurs
after the OnLoad( ) event where Russ wants to run his code.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.


Boyd "Hi Tech Coach" via AccessMonster.com said:
Yes you can put just about anything into a text string that passes an on
open
arg.

I would also suggest that you try using the this in your On Load event:

If not Me.NewRecord then
Set rs = Me.Recordset.Clone
rs.FindFirst stlinkcriteria
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
end if


Hope this helps....

Russ said:
Thanx Gunny - Can you put anything in the OpenArgs area? I've never used
that
before...
Hi, Russ.

[quoted text clipped - 59 lines]
me.form.newrecord, but either way it came back with a 0. Any help
would be
greatly appreciated...
 
You are correct. The NewRecord property is not avain=le until the On Current
event fires.



'69 Camaro said:
The code within this IF block will never execute if placed in the OnLoad( )
event of a form. It will always be false, no matter whether it's a new
record, the first record, or some other specific record in the record set
that the form is supposed to open to. The Form's NewRecord Property won't
be decernable until the OnCurrent( ) event, which occurs after the OnLoad( )
event where Russ wants to run his code.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.
Yes you can put just about anything into a text string that passes an on
open
[quoted text clipped - 19 lines]

--
Boyd
Hi Tech Coach
http://www.hitechcoach.com


Message posted via AccessMonster.com
 
Back
Top