Public function from next record

sargon

Registered User.
Local time
Today, 08:05
Joined
Mar 13, 2006
Messages
48
I never used VBA before, but I need to create a public function (fc_P) that read all the record from one field (x_date) and after that to create a new field that has in the previous record x_date - 1 (last record should be Now())

x_date
01/01/2022
03/05/2022
08/07/2022

and to generate

fc_P
03/04/2022
08/06/2022
Now()
 
you can use query:

select x_date, Nz(DMin("x_date", "YourTableName", "x_date > #" & Format$(x_date, "mm/dd/yyyy") & "#")-1, Date()) As fc_p from YourTableName;
 
And If I want to create a Public Function?


Public Function fc_p()
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("YourTableName")

Dim strSQL As String


strSQL = "Select x_date, Nz(DMin("x_date", "YourTableName", "x_date > #" & Format$(x_date, "mm/dd/yyyy") & "#")-1, Date()) As fc_p from YourTableName;"

Set fc_p = db.OpenRecordset(strSQL)

End Function
 
the function is somewhat the same:
Code:
Public Function fnx(ByVal dte) As Date
    fnx = Nz(DMin("x_date", "YourTableName", "x_date > #" & Format$(dte, "mm/dd/yyyy") & "#")-1, Date())
End Function

you need to pass a Date to the function.
but the query itself is sufficient.
 
Fără titlu.jpg


Something is not working...
 

Attachments

Try changing the signature of the function slightly to specifically type your parameter:
Code:
Public Function fnx(ByVal dte As Date) As Date
' ...
What datatype is field x_date?
 
see query 2 in design view.
and see the query 3
 

Attachments

Users who are viewing this thread

Back
Top Bottom