![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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. . . |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |