dbTalk Databases Forums  

Open Form to Specific Record

comp.databases.ms-access comp.databases.ms-access


Discuss Open Form to Specific Record in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
tonynahon@gmail.com
 
Posts: n/a

Default Open Form to Specific Record - 03-24-2009 , 04:22 PM






Hello Everyone: Can anyone help me with this problem? I need to open a
form to a specific record, and I am using the following code:

Private Sub Form_Open(Cancel As Integer)

Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID] = 24"
Me.Bookmark = rs.Bookmark

Set rs = Nothing

End Sub

I have used this technique before in the Form_Open event and it has
worked OK. However, I have recently had a problem where using the code
in the Form_Open event, the form opens to the first record in the
Query, not the specified record. In this example the record (ContactID
= 24) does exist and it is possible to navigate to it once the form is
open. I found some sample code on Allen Browne's website which does
essentially the same thing, but in the Form_Load event - I tried this
and it works for me.

I don't know what I have done differently in this database to cause
this behavior - anyone have any ideas?

Thanks. . .

Reply With Quote
  #2  
Old   
Wayne Gillespie
 
Posts: n/a

Default Re: Open Form to Specific Record - 03-24-2009 , 06:46 PM






On Tue, 24 Mar 2009 15:22:10 -0700 (PDT), tonynahon (AT) gmail (DOT) com wrote:

Quote:
Hello Everyone: Can anyone help me with this problem? I need to open a
form to a specific record, and I am using the following code:

Private Sub Form_Open(Cancel As Integer)

Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID] = 24"
Me.Bookmark = rs.Bookmark

Set rs = Nothing

End Sub

I have used this technique before in the Form_Open event and it has
worked OK. However, I have recently had a problem where using the code
in the Form_Open event, the form opens to the first record in the
Query, not the specified record. In this example the record (ContactID
= 24) does exist and it is possible to navigate to it once the form is
open. I found some sample code on Allen Browne's website which does
essentially the same thing, but in the Form_Load event - I tried this
and it works for me.

I don't know what I have done differently in this database to cause
this behavior - anyone have any ideas?

Thanks. . .
The Form_Load event is the correct event to use as this is the first event that
fires after the data has been loaded in the form.
The Form_Open event should never be used for any code which is required to work
with the form's underlying data.

Wayne Gillespie
Gosford NSW Australia


Reply With Quote
  #3  
Old   
Allen Browne
 
Posts: n/a

Default Re: Open Form to Specific Record - 03-25-2009 , 06:45 AM



Also, test whether the FindFirst worked, or results in a NoMatch.

--
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.
"Wayne Gillespie" <bestfit (AT) NObestfitSPAMsoftwarePLEASE (DOT) com.au> wrote in
message news:4evis413jmpqh0jvb79i3j87aoj6fe74hp (AT) 4ax (DOT) com...
Quote:
On Tue, 24 Mar 2009 15:22:10 -0700 (PDT), tonynahon (AT) gmail (DOT) com wrote:

Hello Everyone: Can anyone help me with this problem? I need to open a
form to a specific record, and I am using the following code:

Private Sub Form_Open(Cancel As Integer)

Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID] = 24"
Me.Bookmark = rs.Bookmark

Set rs = Nothing

End Sub

I have used this technique before in the Form_Open event and it has
worked OK. However, I have recently had a problem where using the code
in the Form_Open event, the form opens to the first record in the
Query, not the specified record. In this example the record (ContactID
= 24) does exist and it is possible to navigate to it once the form is
open. I found some sample code on Allen Browne's website which does
essentially the same thing, but in the Form_Load event - I tried this
and it works for me.

I don't know what I have done differently in this database to cause
this behavior - anyone have any ideas?

Thanks. . .

The Form_Load event is the correct event to use as this is the first event
that
fires after the data has been loaded in the form.
The Form_Open event should never be used for any code which is required to
work
with the form's underlying data.

Wayne Gillespie
Gosford NSW Australia


Reply With Quote
  #4  
Old   
tonynahon@gmail.com
 
Posts: n/a

Default Re: Open Form to Specific Record - 03-25-2009 , 10:29 AM



On Mar 25, 5:45*am, "Allen Browne" <AllenBro... (AT) SeeSig (DOT) Invalid> wrote:
Quote:
Also, test whether the FindFirst worked, or results in a NoMatch.

--
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.
"Wayne Gillespie" <best... (AT) NObestfitSPAMsoftwarePLEASE (DOT) com.au> wrote in
messagenews:4evis413jmpqh0jvb79i3j87aoj6fe74hp (AT) 4ax (DOT) com...

On Tue, 24 Mar 2009 15:22:10 -0700 (PDT), tonyna... (AT) gmail (DOT) com wrote:

Hello Everyone: Can anyone help me with this problem? I need toopena
formto aspecificrecord, and I am using the following code:

Private Sub Form_Open(Cancel As Integer)

Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID] = 24"
Me.Bookmark = rs.Bookmark

Set rs = Nothing

End Sub

I have used this technique before in the Form_Open event and it has
worked OK. However, I have recently had a problem where using the code
in the Form_Open event, theformopens to the firstrecordin the
Query, not the specifiedrecord. In this example therecord(ContactID
= 24) does exist and it is possible to navigate to it once theformis
open. I found some sample code on Allen Browne's website which does
essentially the same thing, but in theForm_Loadevent - I tried this
and it works for me.

I don't know what I have done differently in this database to cause
this behavior - anyone have any ideas?

Thanks. . .

TheForm_Loadevent is the correct event to use as this is the first event
that
fires after the data has been loaded in theform.
The Form_Open event should never be used for any code which is requiredto
work
with theform'sunderlying data.

Wayne Gillespie
Gosford NSW Australia
Wayne; Allen: Thanks to you both for responding to my post - your
comments are very helpful.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.