Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dialog Box opens Record in a Form ---error

Status
Not open for further replies.

Milin

Technical User
Jan 5, 2000
33
US
Hello...<br>I am trying to recreate an example I found in the MS Access97 Step By Step book p.179). It is where you create a dialog box (form) using a list box to pick a record to go to a specific record on the main form.<br><br>This is the code from the book, modified for my<br>database:<br><br>Private Sub Command4_Click()<br>Dim rst As Recordset<br>Set rst = Forms!MasterVIC.RecordsetClone<br>rst.FindFirst &quot;CallerNo = &quot; & List2<br>Forms!MasterVIC.Bookmark = rst.Bookmark<br>DoCmd.Close acForm, &quot;GoToRecordDialog&quot;<br>End Sub<br><br>...wth MasterVIC being the main form, GoToRecordDialog being the form with the list box in it. CallerNo is my record identifying number.&nbsp;&nbsp;When I click the button to run this (with both forms open) I get &quot;run-time error 3021 no current record&quot; and debugging highlights the Forms!MasterVIC.Bookmark = rst.Bookmark line. There is an existing record in the database.&nbsp;&nbsp;Could the fact that I have a subform inside MasterVIC be wreaking it?<br><br>What could I be doing wrong?<br><br><br><br>
 
Milin,<br>You should not set a bookmark unless you know the record was found.&nbsp;&nbsp;After the FindFirst, you should do this instead:<br>If rst.NoMatch then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msgbox &quot;Record not found&quot;<br>Else<br>&nbsp;&nbsp;&nbsp;&nbsp;Forms!MasterVIC.Bookmark = rst.Bookmark<br>End If<br>&nbsp;No current record may mean that the recordset is empty or the recordsetclone was never positioned anywhere (via a MoveFirst or FindFirst).<br>--Jim
 
JIM...<br>Thanks for the help. I set up the code and on every record I click to try to open, I get the &quot;record not found&quot; message box that I set up. I can see the &quot;CallerNo&quot; in the main table, so I know the records are there. What do you mean about the recordsetclone not being positioned???<br>Here is my current code:<br><br>Private Sub Command4_Click()<br>Dim rst As Recordset<br>Set rst = Forms!MasterVIC.RecordsetClone<br>rst.FindFirst &quot;CallerNo = &quot; & List2<br>If rst.NoMatch Then<br>MsgBox &quot;record not found&quot;<br>Else<br>Forms!MasterVIC.Bookmark = rst.Bookmark<br>End If<br>DoCmd.Close acForm, &quot;GoToRecordDialog&quot;<br>End Sub<br><br>Thanks!<br><br>
 
Milin,<br>Two things to check...<br>First, you need to use Me!List2 instead of List2, but to be sure, put a breakpoint on the FindFirst line (F9), then click the button.&nbsp;&nbsp;When the code stops there, go in the debug window and type ?me!list2<br>See what it gives you.&nbsp;&nbsp;You may need a different column from the listbox other than the bound one.<br>&nbsp;<br>Next, if that doesn't work, check if the recordset is bookmarkable, by doing<br>If rst.bookmarkable then<br>{tab] 'do the FindFirst etc.<br>Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'you're out of luck, cant set bookmark on this recordset<br>End if<br>&nbsp;<br>--Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top