Runtime error 3021 - no current record

Danick

Registered User.
Local time
Today, 15:41
Joined
Sep 23, 2008
Messages
377
Having a little trouble getting this code to work.
Using a command button to requery a field on the main form and keep the place in the subform.
This works fine if there is a record in the subform, but get an error if there are no records.


Code:
Dim strBookmark As String
strBookmark = Me.[SubformName].Form.Bookmark
Me.MainFormField.Requery
Me.[SubformName].Form.Requery
Me.[SubformName].Form.Bookmark = strBookmark


How can I bypass the bookmark portion of the code and just requery the MainFormField when there are no records in the subform to bookmark.
 
A bookmark is not a string. Try Variant.

Tried Dim strBookmark As Variant
Same error

I think I need to use an if statement and only Bookmark and requery the subform IF there are any records in the subform.
 
I think I got it working.

Code:
Dim strBookmark As String
If IsNull(Me.[SubformName].Form.SubControlField Then
Me.MainFormField.Requery
Exit Sub
Else
strBookmark = Me.[SubformName].Form.Bookmark
Me.MainFormField.Requery
Me.[SubformName].Form.Requery
Me.[SubformName].Form.Bookmark = strBookmark
End If

Just testing it now, but so far so good...
 
Remember...a bookmark is NOT a string. You are probably going to want to look at the RecordCount of the SubForm.
 
Remember...a bookmark is NOT a string. You are probably going to want to look at the RecordCount of the SubForm.


Thanks for the comment. I did try it as a variant and it didn’t make a difference (still got the error) so I went back to using it as a string. And after doing a little research I noticed that Microsoft also remarks to use it as a string in their Northwind database. Check it out here:

https://msdn.microsoft.com/en-us/library/office/ff823084.aspx

Anyway, it’s working now – and you know what they say, If it ain’t broke…

Thanks for always helping out and Have a great day!!!
 
Hmm...I see: Dim varBookmark As Variant
I would also add that the .Bookmark is a property of a Recordset and not the Form.
 
Hmm...I see: Dim varBookmark As Variant
I would also add that the .Bookmark is a property of a Recordset and not the Form.

You're right. I wasn't looking at the actual code. I was reading the remarks section. Here's an excerpt from the third paragraph of that section.


"...There is no limit to the number of bookmarks you can establish. To create a bookmark for a record other than the current record, move to the desired record and assign the value of the Bookmark property to a String variable that identifies the record...."

And I've seen it used this way in a number of applications. Do you think this could cause an issue at some point in the future if I don't change all my bookmark VBAs to Variants
 
It could be that Access is coercing the Variant into a String so I'm not sure about your answer.
 

Users who are viewing this thread

Back
Top Bottom