Continuous form - is record selected

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!
terpsichoreAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wilder1626Commented:
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

IrogSintaCommented:
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
terpsichoreAuthor Commented:
Gives the same error.
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

terpsichoreAuthor 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).
IrogSintaCommented:
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
terpsichoreAuthor Commented:
that is OK - whether the first record, or another record.
I'm trying to trap if NO record is selected.
Rey Obrero (Capricorn1)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
Gustav BrockCIOCommented:
> 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
terpsichoreAuthor Commented:
Thank you.
IrogSintaCommented:
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
terpsichoreAuthor Commented:
yes - recordcount (not 'count').
terpsichoreAuthor Commented:
sorry - I see 3 people answered almost simultaneously. Thank you all.
IrogSintaCommented:
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
terpsichoreAuthor Commented:
not sure how I can allocate the points, then.
In any case, the 'recordcount' was the element I was lacking.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.