Link to home
Create AccountLog in
Avatar of WavyGravy
WavyGravyFlag for United States of America

asked on

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!
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

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)

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
Avatar of WavyGravy

ASKER

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.
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
Got it.  Any way to make it update after inputting data in the visits subform?
in the afterupdate of the subform, try this

me.parent.recalc
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

where is the Textbox located? and what is the name of the textbox that you used?
The textbox is located in the main form named "clients"

"visits subform" renders within the clients form.

Right now the textbox is named "Text284"
test this

Private Sub visits_subform_AfterUpdate()
  '  Me.Parent.Recalc

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

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

and it updates automagically!

/gustav
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

place this line of code in the  Control Source of Text284


= 30 - DCount("*", "visits", "clientID=" & Me.clientID)

place this line of code in the  Control Source of Text284


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

Says that you can't assign a value to this object.
can you upload your db?
Same error for the second line of code you suggested as well.

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

<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.
They're both using clientID.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Works like a charm!  Thanks!
Superb help!