Luclarie
New member
- Local time
- Yesterday, 21:39
- Joined
- Mar 20, 2010
- Messages
- 2
Hi, intermediate novice here and I'm stumped trying to create a very simple DLAST in a query using SQL.
The plan is to create this into vb SQL but for now working with the query grid...
Every day we enter kg. amounts into a tbl, usually it's once a day, but it can sometimes be more than once a day. I'd like to create a dlast to get the last kg. entry in the future entry (it's descending) but I don't want to use the detail ID, what if someone forgets an earlier entry and then has a earlier date but later detail id?
entry_date
So I forced the entry_date into a serial in qry 1, and now in qry 2 trying to create SQL query for Dlast using serial1_date and serial2_date as it would seem the most logical thing to do -- What I'm not sure of is the formatting, thus the code could be wrong...
tbl_daily_entry
entry_date (format date - nothing special)
entry_amount_kg (format single, fixed 2 (looks like this: 00.00)
qry_1
entry_kg:entry_amount_kg
serial1_date: (CDbl([entry_date]))
serial2_date: (CDbl([entry_date]))
qry2:
LAST_ENTRY
Last("[entry_kg]","qry_1", [serial1_date] < [serial2_date])
Questions
Is the tbl fields correct formats?
Since serials are now double format shouldn't they register as numbers?
&&&&&&
Any suggestions would be most helpful -
thank you!
DSum (Dlast) NOTES:
' *************************** '
' ***************************
' Typical Use
' Numerical values. Replace "number" with the number to use.
variable = DLast("[FieldName]", "TableName", "[Criteria] = number")
' Strings. Numerical values. Replace "string" with the string to use.
variable = DLast("[FieldName]", "TableName", "[Criteria]= 'string'")
' Dates. Replace "date" with the string to use.
variable = DLast("[FieldName]",, "TableName", "[Criteria]= #date#")
***************************
Referring to a control on a form
' Numerical values
variable = DLast("[FieldName]", "TableName", "[Criteria] = " & Forms!FormName!ControlName)
' Strings
variable = DLast("[FieldName]", "TableName", "[Criteria] = '" & Forms!FormName!ControlName & "'")
' Dates
variable = DLast("[FieldName]" , "TableName", "[Criteria] = #" & Forms!FormName!ControlName & "#")
***************************
Combinations
Multiple types of criteria
variable = DLast("[FieldName]", "TableName", "[Criteria1] = " & Forms!
[FormName]![Control1] _
& " AND [Criteria2] = '" D & Forms![FormName]![Control2] & "'" _
& " AND [Criteria3] =#" D & Forms![FormName]![Control3] & "#")
' Use two fields from a single record.
variable = DLast("[LastName] & ', ' & [FirstName]", "tblPeople", "[PrimaryKey] = 7")
' Expressions
variable = DLast("[Field1] + [Field2]" d , "tableName", "[PrimaryKey] = 7")
' Control Structures
variable = DLast("IIf([LastName] Like 'Smith', 'True', 'False')", "table‐Name", "[PrimaryKey] = 7")
***************************
The plan is to create this into vb SQL but for now working with the query grid...
Every day we enter kg. amounts into a tbl, usually it's once a day, but it can sometimes be more than once a day. I'd like to create a dlast to get the last kg. entry in the future entry (it's descending) but I don't want to use the detail ID, what if someone forgets an earlier entry and then has a earlier date but later detail id?
entry_date
So I forced the entry_date into a serial in qry 1, and now in qry 2 trying to create SQL query for Dlast using serial1_date and serial2_date as it would seem the most logical thing to do -- What I'm not sure of is the formatting, thus the code could be wrong...
tbl_daily_entry
entry_date (format date - nothing special)
entry_amount_kg (format single, fixed 2 (looks like this: 00.00)
qry_1
entry_kg:entry_amount_kg
serial1_date: (CDbl([entry_date]))
serial2_date: (CDbl([entry_date]))
qry2:
LAST_ENTRY
Questions
Is the tbl fields correct formats?
Since serials are now double format shouldn't they register as numbers?
&&&&&&
Any suggestions would be most helpful -
thank you!
DSum (Dlast) NOTES:
' *************************** '
' ***************************
' Typical Use
' Numerical values. Replace "number" with the number to use.
variable = DLast("[FieldName]", "TableName", "[Criteria] = number")
' Strings. Numerical values. Replace "string" with the string to use.
variable = DLast("[FieldName]", "TableName", "[Criteria]= 'string'")
' Dates. Replace "date" with the string to use.
variable = DLast("[FieldName]",, "TableName", "[Criteria]= #date#")
***************************
Referring to a control on a form
' Numerical values
variable = DLast("[FieldName]", "TableName", "[Criteria] = " & Forms!FormName!ControlName)
' Strings
variable = DLast("[FieldName]", "TableName", "[Criteria] = '" & Forms!FormName!ControlName & "'")
' Dates
variable = DLast("[FieldName]" , "TableName", "[Criteria] = #" & Forms!FormName!ControlName & "#")
***************************
Combinations
Multiple types of criteria
variable = DLast("[FieldName]", "TableName", "[Criteria1] = " & Forms!
[FormName]![Control1] _
& " AND [Criteria2] = '" D & Forms![FormName]![Control2] & "'" _
& " AND [Criteria3] =#" D & Forms![FormName]![Control3] & "#")
' Use two fields from a single record.
variable = DLast("[LastName] & ', ' & [FirstName]", "tblPeople", "[PrimaryKey] = 7")
' Expressions
variable = DLast("[Field1] + [Field2]" d , "tableName", "[PrimaryKey] = 7")
' Control Structures
variable = DLast("IIf([LastName] Like 'Smith', 'True', 'False')", "table‐Name", "[PrimaryKey] = 7")
***************************