Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing field names to a Function or Sub

Status
Not open for further replies.

Kenny1943

MIS
Jul 18, 2003
13
US
I have a table that contains dates of completion for a process. There are five different dates for each record. Each date represents the completeion of a step in the process. I am trying to calculate the workings days between each of these 5 dates. I use a function to calc the working days.

This is the code I wrote to update the working days once it is calculated. CountWorkdays is a function used to calculate the days.

How can I pass the field names to the Sub so I can call this and use it with each of the updates?

Sub CalcDays(sTable As String, sUpdateField As String, sDatefield As String, eDateField As String)

Dim db As dao.Database, rst As dao.Recordset
Set db = CurrentDb

Set rst = db.OpenRecordset(sTable, dbOpenDynaset)

Do Until rst.EOF
With rst
.Edit
!sUpdateField = (CountWorkdays(!sDatefield, !eDateField))
.Update
.MoveNext
End With
Loop

rst.Close
db.Close
End Sub
 
function CountWorkDays(Date1 as date, date2 as date) as long
CountWorkDays=datediff("d",date1,date2)
end function

This function will return the days between the two dates, not just the weekdays.

BB
 
BigBrother

I have a function to calc the works days. But what I need is a generic sub to update the work days once calculated. How can I pass the field names to the Sub?
 


Use the Fields collection to find the column(s) you want to update using the strings passed as parameters:


With rst
.Edit
.Fields(sUpdateField) = (countWorkdays(.Fields(sDatefield), .Fields(eDateField)))
.Update
.MoveNext
End With



Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
MarkSweetland

This is works great. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top