need formula \ code advice. min date (1 Viewer)

TipsyWolf

Member
Local time
Today, 09:17
Joined
Mar 20, 2024
Messages
112
hello guys :)
and im here today with i think easy question for pro-access users here.

i have 1main table and 1 sub table (one to many)
main table has general info. sub table has few records per 1 record from main table.
all focus to date field in sub table.

how do i return min. date into main table.
for example
1st record of main table has 2 records in sub table. these 2 records have extra info, including date. i need to get minimum date and put it to main table under (lest say min. date field)

i know i can do it by query , but its hard for me later to use this min. date for my further furmals like dcount or iif(sum())

suggestions, advice are very welcome :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:17
Joined
Sep 21, 2011
Messages
14,361
DMin() ?
However I would not store it again.
Could another record be added with an earlier date?
 

TipsyWolf

Member
Local time
Today, 09:17
Joined
Mar 20, 2024
Messages
112
DMin() ?
However I would not store it again.
Could another record be added with an earlier date?
Code:
=DMin( [Tactions]![DueDate] )
it says error... containing a wrong number of arguments,
i put this formula into Control Source of duedate text box

but how does it know that i need min date only records that related to 1 record of parent table ?
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 07:17
Joined
Sep 21, 2011
Messages
14,361
Perhaps using criteria? :(
Have you ever thought of looking up the syntax for anything? :(


I would probably just set it on the current event of the main form, but that is me. :)
 
Last edited:

TipsyWolf

Member
Local time
Today, 09:17
Joined
Mar 20, 2024
Messages
112
Perhaps using criteria? :(
Have you ever thought of looking up the sytax for anything? :(


I would probably just set it on the current event of the main form, but that is me. :)
i read about dmin a bit more and i tired this
Code:
=DMin("[duedate]";"[Tactions]";"[RiskID]"=" & [RiskID]")
but my textbox is blank :(
 

Josef P.

Well-known member
Local time
Today, 08:17
Joined
Feb 2, 2023
Messages
833
The Criteria parameter is false.

Check:
Code:
dim Criteria as String
Criteria = "[RiskID]"=" & [RiskID]"
debug.print Criteria, "oops :-)"

You can also test directly in the Immediate window (VBA editor):
? "[RiskID]"=" & [RiskID]"


Use:
"[RiskID]=" & [RiskID]
 

TipsyWolf

Member
Local time
Today, 09:17
Joined
Mar 20, 2024
Messages
112
The Criteria parameter is false.

Check:
Code:
dim Criteria as String
Criteria = "[RiskID]"=" & [RiskID]"
debug.print Criteria, "oops :-)"

You can also test directly in the Immediate window (VBA editor):
? "[RiskID]"=" & [RiskID]"


Use:
"[RiskID]=" & [RiskID]
already did it in post #5 here
 

Josef P.

Well-known member
Local time
Today, 08:17
Joined
Feb 2, 2023
Messages
833
Have you looked at the printout in the immediate window?
What was the result?

The expression "[RiskID]"=" & [RiskID]" compares 2 strings ("[RiskID]" and " & [RiskID]") and the result is False.

To compare:
=DMin("[duedate]";"[Tactions]";"[RiskID]"=" & [RiskID]") <-- #5
vs
=DMin("[duedate]";"[Tactions]";"[RiskID]=" & [RiskID])
 

TipsyWolf

Member
Local time
Today, 09:17
Joined
Mar 20, 2024
Messages
112
Have you looked at the printout in the immediate window?
What was the result?

To compare:
=DMin("[duedate]";"[Tactions]";"[RiskID]"=" & [RiskID]") <-- #5
vs
=DMin("[duedate]";"[Tactions]";"[RiskID]=" & [RiskID])
it says #Name? error
i even changed format fot the textbox to 'short date', but still #Name? error :(
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:17
Joined
Feb 28, 2001
Messages
27,229
for example
1st record of main table has 2 records in sub table. these 2 records have extra info, including date. i need to get minimum date and put it to main table under (lest say min. date field)

The problem is related to understanding queries. You NEVER store data in a main table that was derived from an arbitrary number of child records. Instead you make a query that represents a JOIN of the parent to its children. This implies there is a primary key on the main that can / does act like a foreign key in the child tables. If so, you can do group-by operations. The question is whether for this purpose there is any other data from the child table that you needed to pull up to the main table besides this date. If not, this should be quite simple.

i know i can do it by query , but its hard for me later to use this min. date for my further furmals like dcount or iif(sum())

This implies that you are working too hard. You are probably trying to use the main table but instead should be using a query to feed the next set of formulas. Access rarely cares that a recordset is from a table. It likes query-based recordsets just as well.
 

mike60smart

Registered User.
Local time
Today, 07:17
Joined
Aug 6, 2017
Messages
1,913
Hi
If you base the Main Form on a Select Query then you can add the criteria.

See the attached FRiskPage
 

Attachments

  • RiskDB new.zip
    717.9 KB · Views: 22

LarryE

Active member
Local time
Yesterday, 23:17
Joined
Aug 18, 2021
Messages
592
i read about dmin a bit more and i tired this
Code:
=DMin("[duedate]";"[Tactions]";"[RiskID]"=" & [RiskID]")
but my textbox is blank :(
Also, never use brackets in the table argument. "Tactions", not "[Tactions]"
 

tvanstiphout

Active member
Local time
Yesterday, 23:17
Joined
Jan 22, 2016
Messages
232
Also, never use brackets in the table argument. "Tactions", not "[Tactions]"
And never mismatch your double-quotes:
=DMin("duedate";"Tactions";"RiskID=" & Me.RiskID)
(I'm a bit fuzzy on the use of semicolon as an argument separator, but that may be OK in some locales).
 

TipsyWolf

Member
Local time
Today, 09:17
Joined
Mar 20, 2024
Messages
112
Hi
If you base the Main Form on a Select Query then you can add the criteria.

See the attached FRiskPage
hi :)
this one worked for me. i just copied it to my original db and its cool :)
thank you for your help !
 

TipsyWolf

Member
Local time
Today, 09:17
Joined
Mar 20, 2024
Messages
112
@The_Doc_Man
thank you for your suggestion !
i made a query
1712090488035.png


and in my form i put
Code:
=DLookUp("minofduedate";"Qmindate";"[riskID]=" & [riskID])
and it shows me #name? for some reason ...
 

TipsyWolf

Member
Local time
Today, 09:17
Joined
Mar 20, 2024
Messages
112
i really would like to learn how to get data from a query. i underestimate power of query as i see, so even though @mike60smart helped me, i would like to use query as alternative and educational purposes and i would like somehow to Dlookup vales from query to form with [riskID]=" & [riskID]) condition
 

Josef P.

Well-known member
Local time
Today, 08:17
Joined
Feb 2, 2023
Messages
833
This is the label text. The name of the AccessField or Control could be different.
 

Users who are viewing this thread

Top Bottom