We help IT Professionals succeed at work.

Continuous form - is record selected

terpsichore
terpsichore asked
on
Dear experts -
This should be an easy one -
I want to see if a record is selected in a continuous subform.
The code below was working fine, except that if NO RECORDS appear under the current filter condition:
If IsNull(Me!sfPartsLines.Form!txtExpense_ID) Then
    MsgBox ("Please select an expense item first.")
    Exit Sub
End If

In that case, I get the error "YOU ENTERED AN EXPRESSION THAT HAS NO VALUE"

Any ideas?

Thanks!
Comment
Watch Question

HI

can you try like this:
 If IsNull(Me.sfPartsLines.Form!txtExpense_ID) Then                     
      MsgBox "Please select an expense item first.", vbOKOnly  
      Exit Sub                                           
  End If      

Open in new window

Is txtExpense_ID bound to a field in the recordsource of your continuous for?  If it is, then I don't see how you can tell that a record was selected by the user because as long as there are records returned, the first record is always going to be the default selection.

Ron

Author

Commented:
Gives the same error.

Author

Commented:
txtExpense_ID IS a bound field.
But it is possible that NO RECORDS are returned or are not in the filter condition.

The situation I'm looking at right now is where the list is empty (i.e. no records returned).
I understand what you're asking but what I'm asking is if there are records, how do you know a user actually made a selection or not since the first record will automatically be selected.

Ron

Author

Commented:
that is OK - whether the first record, or another record.
I'm trying to trap if NO record is selected.
Top Expert 2016

Commented:
try

if Me!sfPartsLines.form.RecordsetClone.Count >0 then
If IsNull(Me!sfPartsLines.Form!txtExpense_ID) Then
     MsgBox ("Please select an expense item first.")
     Exit Sub
 End If
end if
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
> The situation I'm looking at right now is where the list is empty (i.e. no records returned).

Then all you need is:

If Me!sfPartsLines.Form.RecordsetClone.RecordCount = 0 Then
     MsgBox "Please select an expense item first."
     Exit Sub
End If

IsNull(Me!sfPartsLines.Form!txtExpense_ID) will only tell you if you are on new record.

/gustav

Author

Commented:
Thank you.
So the only way a record will not be selected is if there are no records.  Hence, there is no need to tell the user to make a selection.   You can just do:

If Me!sfPartsLines.Form.RecordsetClone.RecordCount = 0 then
      MsgBox ("There are no records matching your filter.")
      Exit Sub
  End If

Open in new window


Ron

Author

Commented:
yes - recordcount (not 'count').

Author

Commented:
sorry - I see 3 people answered almost simultaneously. Thank you all.
I think you were too hasty in selecting an answer.  The solution you selected is not quite right.  Both Gustav and I posted similar solutions that make more sense.  Though I think my message box text is more appropriate.

Ron

Author

Commented:
not sure how I can allocate the points, then.
In any case, the 'recordcount' was the element I was lacking.