Supressing a 'No current record' error message on a form

G

Guest

I have a fixed number of 10 question based records on a table linked to a
form control box., when the user selects an answer, the form automatically
moves to the next question/record; when they finally get to the 10th record,
they have to answer the last question, but when they do, due to the automatic
‘next record’ macro, the form tries to access record ‘11’. And because the
table/form is limited to 10 records, it throws the following error:


No current record. (Error 3021)

You can’t go to the specified record

Is there a way to supress this message and replace it with something more
user friendly, My ideal would be, that it never goes to record 11, and
therefore doesn’t invoke the error message, but instead, simply returns back
to record 10.
 
M

Marshall Barton

efandango said:
I have a fixed number of 10 question based records on a table linked to a
form control box., when the user selects an answer, the form automatically
moves to the next question/record; when they finally get to the 10th record,
they have to answer the last question, but when they do, due to the automatic
‘next record’ macro, the form tries to access record ‘11’. And because the
table/form is limited to 10 records, it throws the following error:

No current record. (Error 3021)
You can’t go to the specified record

Is there a way to supress this message and replace it with something more
user friendly, My ideal would be, that it never goes to record 11, and
therefore doesn’t invoke the error message, but instead, simply returns back
to record 10.


What are you doing to get to the next record?

The form's Cycle property can be set to All Records to
automatically go to the next record when you tab out of the
last control (in the tab list). If the foem's Allow
Additions property os set to No, then the cursoe will stay
on the last record.
 
G

Guest

Hi Marshall,

I am using a macro with a Goto Next Record command. This is based on a user
selecting an answer to a question from a drop-down combo box. This is the
only interaction the user has with the form. A tab key (or any key) would not
be useful as the questions are numerous, and keyboard actiivty would put the
user off.

meanwhile... your comment, "If the form's Allow Additions property is set to
No, then the cursoe will stay on the last record." has cracked the problem.

Thanks for your help.
 
G

Guest

Now that the error:

No current record. (Error 3021)
You can’t go to the specified record

hs been resolved, it throws another error:

'You can't go to the specified record'

'You may be at the end of a recordset'

I realise that the form is at the end of a 'recordset', as it is intended.
How can I supress or deal with this error message pop-up in a more user
friendly way?
 
M

Marshall Barton

I have no idea how to do it in a macro, but the logic is to
check the form's recordset's RecordCount property against
the form's CurrentRecord property.

In VBA it would be:

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext
 
G

Guest

Thanks Marshall, that was a nice elegant solution to my problem. I also
discovered along the way that you can't have a function definition inside a
sub when I convertewd my macro to VBA.

My form works beautifully now!!
 
G

Guest

Hi Marshall,

I spoke too soon... and I think this one is going to be tough to resolve…

The form works ok, until a user completes the last record answer combo box
(Combo_Answer_A).

What seems to happen is the

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext

In the CODE FOR Combo_Answer_A conflicts with the code for the ‘New Test’
button, where;

DoCmd.Requery "Combo_Answer_A"

Throws up on an empty recordset because the

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext

Wants to take precedence over the CODE FOR New Test button


I hope this makes sense (though I may be completely wrong in my
assumptions), and that you can help me resolve this as it is important that
users can focus on the questions, instead of error messages.





CODE FOR Combo_Answer_A

Private Sub Combo_Answer_A_AfterUpdate()
With CodeContextObject
If (.Combo_Answer_A = .Run_Point_Address_A) Then
.answer_box = -1
End If
If (.Combo_Answer_A <> .Run_Point_Address_A) Then
.answer_box = 0
End If
If (.answer_box = -1) Then
' Adds 1 to Tempscorebox
.Tempscore = .Tempscore + 1
End If
If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext
End With

End Sub




CODE FOR New Test button

Private Sub Command14_Click()
stDocName = "QRY_Delete_PointsTest_A"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_A"
DoCmd.SetWarnings True 'enable warnings
Me.Requery
DoCmd.Requery "Combo_Answer_A"
[Combo_Answer_A] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_A"
End Sub
 
G

Guest

Hi Marshall,

I have fixed the 3rd problem now by inserting the following line into my
requery button.

If Me.CurrentRecord = 10 Then Me.Recordset.MoveFirst

heres the complete code just in case there is a better way of doing it.

Private Sub Command16_Click()
If Me.CurrentRecord = 10 Then Me.Recordset.MoveFirst
'checks for last record, if so, then avoids the (for new table)Me.requery
'which avoids requerying an empty deleted table

stDocName = "QRY_Delete_PointsTest_C"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_C"
DoCmd.SetWarnings True 'enable warnings
Me.Requery
DoCmd.Requery "Combo_Answer_C"
[Combo_Answer_C] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_C"

End Sub


Phew, thanks for all your help. much appriecated.

efandango said:
Hi Marshall,

I spoke too soon... and I think this one is going to be tough to resolve…

The form works ok, until a user completes the last record answer combo box
(Combo_Answer_A).

What seems to happen is the

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext

In the CODE FOR Combo_Answer_A conflicts with the code for the ‘New Test’
button, where;

DoCmd.Requery "Combo_Answer_A"

Throws up on an empty recordset because the

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext

Wants to take precedence over the CODE FOR New Test button


I hope this makes sense (though I may be completely wrong in my
assumptions), and that you can help me resolve this as it is important that
users can focus on the questions, instead of error messages.





CODE FOR Combo_Answer_A

Private Sub Combo_Answer_A_AfterUpdate()
With CodeContextObject
If (.Combo_Answer_A = .Run_Point_Address_A) Then
.answer_box = -1
End If
If (.Combo_Answer_A <> .Run_Point_Address_A) Then
.answer_box = 0
End If
If (.answer_box = -1) Then
' Adds 1 to Tempscorebox
.Tempscore = .Tempscore + 1
End If
If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext
End With

End Sub




CODE FOR New Test button

Private Sub Command14_Click()
stDocName = "QRY_Delete_PointsTest_A"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_A"
DoCmd.SetWarnings True 'enable warnings
Me.Requery
DoCmd.Requery "Combo_Answer_A"
[Combo_Answer_A] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_A"
End Sub


Marshall Barton said:
I have no idea how to do it in a macro, but the logic is to
check the form's recordset's RecordCount property against
the form's CurrentRecord property.

In VBA it would be:

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext
 
M

Marshall Barton

Well that seems to work, but what will you do when you
decide that you need another question?

Better to test for the last record instead of the 10th
record:
If Me.CurrentRecord = Me.Recordset.RecordCount _
Then Me.Recordset.MoveFirst

I have no idea what/why you are opening those queries and
requerying everything, but if it works I can't argue with
it.

The code for the combo's AfterUpdate can be simplified, but
don't use this unless you understand why it does the same
thing.

Private Sub Combo_Answer_A_AfterUpdate()
With CodeContextObject
.answer_box = (.Combo_Answer_A = .Run_Point_Address_A)
.Tempscore = .Tempscore - .answer_box
If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext
End With
End Sub

Your use of CodeContextObject seems inconsistent with the
use of Me. Shouldn't they be the same thing?
--
Marsh
MVP [MS Access]

I have fixed the 3rd problem now by inserting the following line into my
requery button.

If Me.CurrentRecord = 10 Then Me.Recordset.MoveFirst

heres the complete code just in case there is a better way of doing it.

Private Sub Command16_Click()
If Me.CurrentRecord = 10 Then Me.Recordset.MoveFirst
'checks for last record, if so, then avoids the (for new table)Me.requery
'which avoids requerying an empty deleted table

stDocName = "QRY_Delete_PointsTest_C"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_C"
DoCmd.SetWarnings True 'enable warnings
Me.Requery
DoCmd.Requery "Combo_Answer_C"
[Combo_Answer_C] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_C"

End Sub

Phew, thanks for all your help. much appriecated.

efandango said:
I spoke too soon... and I think this one is going to be tough to resolve…

The form works ok, until a user completes the last record answer combo box
(Combo_Answer_A).

What seems to happen is the

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext

In the CODE FOR Combo_Answer_A conflicts with the code for the ‘New Test’
button, where;

DoCmd.Requery "Combo_Answer_A"

Throws up on an empty recordset because the

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext

Wants to take precedence over the CODE FOR New Test button


I hope this makes sense (though I may be completely wrong in my
assumptions), and that you can help me resolve this as it is important that
users can focus on the questions, instead of error messages.

CODE FOR Combo_Answer_A

Private Sub Combo_Answer_A_AfterUpdate()
With CodeContextObject
If (.Combo_Answer_A = .Run_Point_Address_A) Then
.answer_box = -1
End If
If (.Combo_Answer_A <> .Run_Point_Address_A) Then
.answer_box = 0
End If
If (.answer_box = -1) Then
' Adds 1 to Tempscorebox
.Tempscore = .Tempscore + 1
End If
If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext
End With

End Sub

CODE FOR New Test button

Private Sub Command14_Click()
stDocName = "QRY_Delete_PointsTest_A"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_A"
DoCmd.SetWarnings True 'enable warnings
Me.Requery
DoCmd.Requery "Combo_Answer_A"
[Combo_Answer_A] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_A"
End Sub


Marshall Barton said:
I have no idea how to do it in a macro, but the logic is to
check the form's recordset's RecordCount property against
the form's CurrentRecord property.

In VBA it would be:

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext


efandango wrote:
Now that the error:

No current record. (Error 3021)
You can’t go to the specified record

hs been resolved, it throws another error:

'You can't go to the specified record'

'You may be at the end of a recordset'

I realise that the form is at the end of a 'recordset', as it is intended.
How can I supress or deal with this error message pop-up in a more user
friendly way?
 
G

Guest

I have a complex setup to to a relatively simple thing:


I have a form that lists 10 questions in a text box, I have another box with
the answer. I have a combo that lists the 10 possible answers. The user just
selects the answer, and the recordset advances to the next question.
Along the way, a score is kept via the

If (.answer_box = -1) Then
' Adds 1 to Tempscorebox
.Tempscore = .Tempscore + 1

after the 10th question, the answer data is stored in another table, via the
New Test button.

The reason for the 'make table' is because I need the list of top 10 to be
static, until the user decides to request another new top 10 (via a requery),
allowing the user to ‘requery’ the underlying query from within the form to
create a new list from the underlying query.

The important thing is that the top 10 recordset is a 'random' list taken
from a table feeder list of 500 records.

If I ran it directly from the query bypassing the Feeder table, the
accompying ‘answer combo box’ would be out of sync with the question
recordset, as when the form opens the combo box will requery the underlying
table, and throw up a different set of 10 answers, hence the need to place
the recordset in a ‘fixed’ feeder table. Guarenteeing that the ‘Address box’
and ‘answer combo’ reads from the same queryset

another consideration was the ‘answer combo’ has to mix up the list
otherwise the offered answers exactly mirror the questions recordset, which .
Unless you know of a way to make ‘control Source list’ appear random in the
combo box from a table.

I will look at your other suggestions for the combo and testing for last
record, I’m sure they will be a better solution and may take me closer to
resolving some of the issues described above.


To summarise.

I want a user to be able to run a 10 question form from a master list of
hundreds of questions. Be bale to have a running score, and ultimately
deliver the results to another table for other analsys, such as progress
charts, etc.

These tests are ongoing over a very long period of time, and new questions
are added over the course of months.

I am not an expreienced databaser/programmer, but not green either. I’m not
sure where I would rank myself, but I am usually determined enough to find
the solutions. And with the help/advice of people such as yourselves, have
learned a fair bit along the way.

Regards

Eric







Marshall Barton said:
Well that seems to work, but what will you do when you
decide that you need another question?

Better to test for the last record instead of the 10th
record:
If Me.CurrentRecord = Me.Recordset.RecordCount _
Then Me.Recordset.MoveFirst

I have no idea what/why you are opening those queries and
requerying everything, but if it works I can't argue with
it.

The code for the combo's AfterUpdate can be simplified, but
don't use this unless you understand why it does the same
thing.

Private Sub Combo_Answer_A_AfterUpdate()
With CodeContextObject
.answer_box = (.Combo_Answer_A = .Run_Point_Address_A)
.Tempscore = .Tempscore - .answer_box
If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext
End With
End Sub

Your use of CodeContextObject seems inconsistent with the
use of Me. Shouldn't they be the same thing?
--
Marsh
MVP [MS Access]

I have fixed the 3rd problem now by inserting the following line into my
requery button.

If Me.CurrentRecord = 10 Then Me.Recordset.MoveFirst

heres the complete code just in case there is a better way of doing it.

Private Sub Command16_Click()
If Me.CurrentRecord = 10 Then Me.Recordset.MoveFirst
'checks for last record, if so, then avoids the (for new table)Me.requery
'which avoids requerying an empty deleted table

stDocName = "QRY_Delete_PointsTest_C"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_C"
DoCmd.SetWarnings True 'enable warnings
Me.Requery
DoCmd.Requery "Combo_Answer_C"
[Combo_Answer_C] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_C"

End Sub

Phew, thanks for all your help. much appriecated.

efandango said:
I spoke too soon... and I think this one is going to be tough to resolve…

The form works ok, until a user completes the last record answer combo box
(Combo_Answer_A).

What seems to happen is the

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext

In the CODE FOR Combo_Answer_A conflicts with the code for the ‘New Test’
button, where;

DoCmd.Requery "Combo_Answer_A"

Throws up on an empty recordset because the

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext

Wants to take precedence over the CODE FOR New Test button


I hope this makes sense (though I may be completely wrong in my
assumptions), and that you can help me resolve this as it is important that
users can focus on the questions, instead of error messages.

CODE FOR Combo_Answer_A

Private Sub Combo_Answer_A_AfterUpdate()
With CodeContextObject
If (.Combo_Answer_A = .Run_Point_Address_A) Then
.answer_box = -1
End If
If (.Combo_Answer_A <> .Run_Point_Address_A) Then
.answer_box = 0
End If
If (.answer_box = -1) Then
' Adds 1 to Tempscorebox
.Tempscore = .Tempscore + 1
End If
If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext
End With

End Sub

CODE FOR New Test button

Private Sub Command14_Click()
stDocName = "QRY_Delete_PointsTest_A"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_A"
DoCmd.SetWarnings True 'enable warnings
Me.Requery
DoCmd.Requery "Combo_Answer_A"
[Combo_Answer_A] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_A"
End Sub


:

I have no idea how to do it in a macro, but the logic is to
check the form's recordset's RecordCount property against
the form's CurrentRecord property.

In VBA it would be:

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext


efandango wrote:
Now that the error:

No current record. (Error 3021)
You can’t go to the specified record

hs been resolved, it throws another error:

'You can't go to the specified record'

'You may be at the end of a recordset'

I realise that the form is at the end of a 'recordset', as it is intended.
How can I supress or deal with this error message pop-up in a more user
friendly way?
 
M

Marshall Barton

Tough set of requirements to meet. Congratulations on
getting it to work.

I don't know how I would approach it, but, since I abhor
MakeTable queries, it would probably be something different.

Good luck with all the enhacements you'll want to add in the
future ;-)
--
Marsh
MVP [MS Access]

I have a complex setup to to a relatively simple thing:


I have a form that lists 10 questions in a text box, I have another box with
the answer. I have a combo that lists the 10 possible answers. The user just
selects the answer, and the recordset advances to the next question.
Along the way, a score is kept via the

If (.answer_box = -1) Then
' Adds 1 to Tempscorebox
.Tempscore = .Tempscore + 1

after the 10th question, the answer data is stored in another table, via the
New Test button.

The reason for the 'make table' is because I need the list of top 10 to be
static, until the user decides to request another new top 10 (via a requery),
allowing the user to ‘requery’ the underlying query from within the form to
create a new list from the underlying query.

The important thing is that the top 10 recordset is a 'random' list taken
from a table feeder list of 500 records.

If I ran it directly from the query bypassing the Feeder table, the
accompying ‘answer combo box’ would be out of sync with the question
recordset, as when the form opens the combo box will requery the underlying
table, and throw up a different set of 10 answers, hence the need to place
the recordset in a ‘fixed’ feeder table. Guarenteeing that the ‘Address box’
and ‘answer combo’ reads from the same queryset

another consideration was the ‘answer combo’ has to mix up the list
otherwise the offered answers exactly mirror the questions recordset, which .
Unless you know of a way to make ‘control Source list’ appear random in the
combo box from a table.

I will look at your other suggestions for the combo and testing for last
record, I’m sure they will be a better solution and may take me closer to
resolving some of the issues described above.


To summarise.

I want a user to be able to run a 10 question form from a master list of
hundreds of questions. Be bale to have a running score, and ultimately
deliver the results to another table for other analsys, such as progress
charts, etc.

These tests are ongoing over a very long period of time, and new questions
are added over the course of months.

I am not an expreienced databaser/programmer, but not green either. I’m not
sure where I would rank myself, but I am usually determined enough to find
the solutions. And with the help/advice of people such as yourselves, have
learned a fair bit along the way.

Regards

Eric







Marshall Barton said:
Well that seems to work, but what will you do when you
decide that you need another question?

Better to test for the last record instead of the 10th
record:
If Me.CurrentRecord = Me.Recordset.RecordCount _
Then Me.Recordset.MoveFirst

I have no idea what/why you are opening those queries and
requerying everything, but if it works I can't argue with
it.

The code for the combo's AfterUpdate can be simplified, but
don't use this unless you understand why it does the same
thing.

Private Sub Combo_Answer_A_AfterUpdate()
With CodeContextObject
.answer_box = (.Combo_Answer_A = .Run_Point_Address_A)
.Tempscore = .Tempscore - .answer_box
If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext
End With
End Sub

Your use of CodeContextObject seems inconsistent with the
use of Me. Shouldn't they be the same thing?
--
Marsh
MVP [MS Access]

I have fixed the 3rd problem now by inserting the following line into my
requery button.

If Me.CurrentRecord = 10 Then Me.Recordset.MoveFirst

heres the complete code just in case there is a better way of doing it.

Private Sub Command16_Click()
If Me.CurrentRecord = 10 Then Me.Recordset.MoveFirst
'checks for last record, if so, then avoids the (for new table)Me.requery
'which avoids requerying an empty deleted table

stDocName = "QRY_Delete_PointsTest_C"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_C"
DoCmd.SetWarnings True 'enable warnings
Me.Requery
DoCmd.Requery "Combo_Answer_C"
[Combo_Answer_C] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_C"

End Sub

Phew, thanks for all your help. much appriecated.

:
I spoke too soon... and I think this one is going to be tough to resolve…

The form works ok, until a user completes the last record answer combo box
(Combo_Answer_A).

What seems to happen is the

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext

In the CODE FOR Combo_Answer_A conflicts with the code for the ‘New Test’
button, where;

DoCmd.Requery "Combo_Answer_A"

Throws up on an empty recordset because the

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext

Wants to take precedence over the CODE FOR New Test button


I hope this makes sense (though I may be completely wrong in my
assumptions), and that you can help me resolve this as it is important that
users can focus on the questions, instead of error messages.

CODE FOR Combo_Answer_A

Private Sub Combo_Answer_A_AfterUpdate()
With CodeContextObject
If (.Combo_Answer_A = .Run_Point_Address_A) Then
.answer_box = -1
End If
If (.Combo_Answer_A <> .Run_Point_Address_A) Then
.answer_box = 0
End If
If (.answer_box = -1) Then
' Adds 1 to Tempscorebox
.Tempscore = .Tempscore + 1
End If
If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext
End With

End Sub

CODE FOR New Test button

Private Sub Command14_Click()
stDocName = "QRY_Delete_PointsTest_A"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_A"
DoCmd.SetWarnings True 'enable warnings
Me.Requery
DoCmd.Requery "Combo_Answer_A"
[Combo_Answer_A] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_A"
End Sub


:

I have no idea how to do it in a macro, but the logic is to
check the form's recordset's RecordCount property against
the form's CurrentRecord property.

In VBA it would be:

If Me.CurrentRecord < Me.Recordset.RecordCount _
Then Me.Recordset.MoveNext


efandango wrote:
Now that the error:

No current record. (Error 3021)
You can’t go to the specified record

hs been resolved, it throws another error:

'You can't go to the specified record'

'You may be at the end of a recordset'

I realise that the form is at the end of a 'recordset', as it is intended.
How can I supress or deal with this error message pop-up in a more user
friendly way?
 

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