Displaying Days Remaining in Access Form

I am currently developing a system that allows an individual to record information on a client (first name, last name, etc.).  This information is stored in a table named client.

A client can make visits to the facility.  When they do, their visit is logged in the visits table, which records the date they came, and what area they occupied.

Anyway, the clients information is entered into the form, while the visit is logged within a subform.  How can I create a label on the form that will count the number of visits a client has made, and then subtract that number from 30?

Any and all help is greatly appreciated.  Thanks!
LVL 1
WavyGravyAsked:
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.

Rey Obrero (Capricorn1)Commented:
you can use this codes in the current event of the form
better using an unbound textbox that you will format to look like a label

me.text1=30-dcount("*","visitstable","custID=" & me.custID)

0
Gustav BrockCIOCommented:
No code is needed.
Use this expression that updates automatically:

=[subChild].[Form].[RecordsetClone].[RecordCount]

where subChild is not the name of the subform but the name of the subform control on the parent form holding the subform.

/gustav
0
WavyGravyAuthor Commented:
capricorn1, do you know of a way to have the textbox update without having to click it, or really perform any action?  I'm using Access 2010 if it matters.

cactus_data, the name of my subform control is "visits" for the visits table, right?  The expression syntax is confusing to me, I apologize.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Rey Obrero (Capricorn1)Commented:
place the codes in the current event of the form, like this

private sub form_current()

me.text1=30-dcount("*","visitstable","custID=" & me.custID)

end sub
0
WavyGravyAuthor Commented:
Got it.  Any way to make it update after inputting data in the visits subform?
0
Rey Obrero (Capricorn1)Commented:
in the afterupdate of the subform, try this

me.parent.recalc
0
WavyGravyAuthor Commented:
Am I missing something here?  Doesn't want to update after adding a record.
Private Sub visits_subform_AfterUpdate()
    Me.Parent.Recalc
End Sub

Open in new window

0
Rey Obrero (Capricorn1)Commented:
where is the Textbox located? and what is the name of the textbox that you used?
0
WavyGravyAuthor Commented:
The textbox is located in the main form named "clients"

"visits subform" renders within the clients form.

Right now the textbox is named "Text284"
0
Rey Obrero (Capricorn1)Commented:
test this

Private Sub visits_subform_AfterUpdate()
  '  Me.Parent.Recalc

    me.parent.text284=30-dcount("*","visitstable","custID=" & me.custID)
End Sub
0
Gustav BrockCIOCommented:
Nothing confusing about:

=[Visit].[Form].[RecordsetClone].[RecordCount]

and it updates automagically!

/gustav
0
WavyGravyAuthor Commented:
No luck with the following:
Private Sub visits_subform_AfterUpdate()
  '  Me.Parent.Recalc
    Me.Parent.Text284 = 30 - DCount("*", "visits", "clientID=" & Me.clientID)
End Sub

Open in new window

0
Rey Obrero (Capricorn1)Commented:
place this line of code in the  Control Source of Text284


= 30 - DCount("*", "visits", "clientID=" & Me.clientID)
0
Rey Obrero (Capricorn1)Commented:

place this line of code in the  Control Source of Text284


= 30 - DCount("*", "visits", "clientID=" & Forms!clients!clientID)
0
WavyGravyAuthor Commented:
Runtime error.

Says that you can't assign a value to this object.
0
Rey Obrero (Capricorn1)Commented:
can you upload your db?
0
WavyGravyAuthor Commented:
Same error for the second line of code you suggested as well.

Should I remove the form_current and afterupdate sections?
0
Rey Obrero (Capricorn1)Commented:
sorry, remove those codes in the the form_current and afterupdate sections?
0
WavyGravyAuthor Commented:
I'm cleaning out the tables and getting ready to upload a version that you can look at.
0
WavyGravyAuthor Commented:
Here's a stripped version of the DB.  I took all of the code out as well.
WorkInProgress.accdb
0
Rey Obrero (Capricorn1)Commented:
btw, did you set the child/master link fields for the subform?
0
WavyGravyAuthor Commented:
Would that be the same thing as primary and foreign keys?
0
Rey Obrero (Capricorn1)Commented:

<Would that be the same thing as primary and foreign keys?> yes

in the design view of the form, select the subform control, hit F4, select the Data tab and you will see those two properties, click on the (...) and select what was suggested by the wizard.
0
WavyGravyAuthor Commented:
They're both using clientID.
0
Rey Obrero (Capricorn1)Commented:
0

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
WavyGravyAuthor Commented:
Works like a charm!  Thanks!
0
WavyGravyAuthor Commented:
Superb help!
0
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.