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?
 
Rey Obrero (Capricorn1)Commented:
0
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.