passing field and control names as variables

CHAOSinACT

Registered User.
Local time
Today, 17:07
Joined
Mar 18, 2009
Messages
235
i have a very complex claim sheet i'm trying to code.... i want the code as efficient as i can so i'm trying to make a routine that does all the work for each line that i can re-use. to do this i REALLY need to be able to pass names for controls and fields as variables (this never seems to work for me unless i reference the field by number, never even tried by control). the by number route would def suck here....Here's the code i'm working on:

Public Sub LoadRemaining()
Call ProcessRemaining("SiteEstablishment", "SiteEstablishmentLeft", "SiteEstablishmentPercentLeft")


End Sub


Public Sub ProcessRemaining(rstField As String, ValueLeft As String, PercentLeft As String)
On Error GoTo handleError
Dim curTotalClaimed As Currency
Dim curCodeTotal As Currency

Dim rstProjectClaims As DAO.Recordset
Set rstProjectClaims = CurrentDb.OpenRecordset("qryCurrentProjectClaims")

curCodeTotal = rstProjectClaims!Fields(rstField)
Debug.Print curCodeTotal & ":CurrentField Total to be billed"
curTotalClaimed = 0
rstProjectClaims.MoveNext

Do Until rstProjectClaims.EOF
curTotalClaimed = rstProjectClaims!Fields(rstField).Value + curTotalClaimed
rstProjectClaims.MoveNext
Loop

Debug.Print curTotalClaimed & ": Current total claimed"

Me!Controls(ValueLeft) = curTotalClaimed
Me!Controls(ValuePercent) = (curCodeTotal - curTotalClaimed) /
curCodeTotal


ExitHere:
rstProjectClaims.Close
Set rstProjectClaims = Nothing

Exit Sub

handleError:
MsgBox "Error Type: " & Err.Description
GoTo ExitHere
End Sub

Sure this is a no-brainer for someone out there, any ideas?

Thanks in advance.
 
Try

curCodeTotal = rstProjectClaims.Fields(rstField)

Me(ValueLeft) = curTotalClaimed
 
thanks so much worked a charm :)
 
Your "thanks" is thanks enough. I appreciate the thought!
 

Users who are viewing this thread

Back
Top Bottom