NoCurrent record error when calling ReQuery on a subform

A

Anja

Hi everyone,

I am running Access and am using VBA to make a custom app.

I have a tab control and one of the pages has a subform. I query the
currently selected record in the subform by overriding the 'On Current'
event as follows:

Private Sub Form_Current()
Dim rs As Recordset

Set rs = Me.Recordset

If Not rs.EOF Or Not rs.BOF Then
MsgBox rs![FormalName]
End If

End Sub

This works fine. Now, I wanted to requery the subform everytime the tab
control changs pages as the underlying records might have changed.

So, I did the following:

Private Sub TabCtl6_Change()
Me.SuppliersWithUnknownCategories_V_subform.Form.Requery
End Sub

However, this always ends up in the previous method with the error "No
current record.".

I tried Refresh, Recalc and other methods but they do not seem to
refresh the data.

Any ideas how I can query the subform data again properly?

Any help is greatly appreciated.

Thanks,
Anja
 
K

kingston via AccessMonster.com

I don't think that this conditional is working the way you want it to:

"If Not rs.EOF Or Not rs.BOF Then"

Is this where the error occurs? Also, when you set rs, are you sure that
there is a recordset at the Me level? Is the subform where the recordset
resides?
Hi everyone,

I am running Access and am using VBA to make a custom app.

I have a tab control and one of the pages has a subform. I query the
currently selected record in the subform by overriding the 'On Current'
event as follows:

Private Sub Form_Current()
Dim rs As Recordset

Set rs = Me.Recordset

If Not rs.EOF Or Not rs.BOF Then
MsgBox rs![FormalName]
End If

End Sub

This works fine. Now, I wanted to requery the subform everytime the tab
control changs pages as the underlying records might have changed.

So, I did the following:

Private Sub TabCtl6_Change()
Me.SuppliersWithUnknownCategories_V_subform.Form.Requery
End Sub

However, this always ends up in the previous method with the error "No
current record.".

I tried Refresh, Recalc and other methods but they do not seem to
refresh the data.

Any ideas how I can query the subform data again properly?

Any help is greatly appreciated.

Thanks,
Anja
 
A

Anja

kingston said:
I don't think that this conditional is working the way you want it to:

"If Not rs.EOF Or Not rs.BOF Then"

Is this where the error occurs? Also, when you set rs, are you sure that
there is a recordset at the Me level? Is the subform where the recordset
resides?
Hi everyone,

I am running Access and am using VBA to make a custom app.

I have a tab control and one of the pages has a subform. I query the
currently selected record in the subform by overriding the 'On Current'
event as follows:

Private Sub Form_Current()
Dim rs As Recordset

Set rs = Me.Recordset

If Not rs.EOF Or Not rs.BOF Then
MsgBox rs![FormalName]
End If

End Sub

This works fine. Now, I wanted to requery the subform everytime the tab
control changs pages as the underlying records might have changed.

So, I did the following:

Private Sub TabCtl6_Change()
Me.SuppliersWithUnknownCategories_V_subform.Form.Requery
End Sub

However, this always ends up in the previous method with the error "No
current record.".

I tried Refresh, Recalc and other methods but they do not seem to
refresh the data.

Any ideas how I can query the subform data again properly?

Any help is greatly appreciated.

Thanks,
Anja

Hi,

Thanks for the reply. The recordset is definitely there. It works fine
normally... only when I call ReQuery after the tab change event
happens, that is fails.

The error happens on the line:

MsgBox rs![FormalName]

Thanks,
Anja
 
K

kingston via AccessMonster.com

Put a debug stop just before that line and run the code. Check the number of
records in rs by entering the commands:

rs.movelast
rs.recordcount

I think that there will be no records in rs. Therefore the error message is
correct. Since you use an OR in your conditional, it's as good as useless
(the record counter is always going to be something other than .EOF OR .BOF)
I don't think that this conditional is working the way you want it to:
[quoted text clipped - 48 lines]
Message posted via AccessMonster.com

Hi,

Thanks for the reply. The recordset is definitely there. It works fine
normally... only when I call ReQuery after the tab change event
happens, that is fails.

The error happens on the line:

MsgBox rs![FormalName]

Thanks,
Anja
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top