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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Sql String

Status
Not open for further replies.

Krystoff

MIS
Sep 18, 2002
129
US
Hello all, I have a function that I am trying to write to sum a field in a table and pass that number to a form (Call the function from the form)

My function looks like this:

Function GetDays(StartDate, EndDate As Date)

Dim strSQL As String

strSQL = "SELECT SUM(BR_DT.[#ofWorkDays]) AS [Days]FROM BR_DT Where (((BR_DT.[BR Date]) Between #" & [StartDate] & "# And #" & [EndDate] & "#))"

End Function

StartDate and EndDate I pass into the function from the form.

I placed a text box on the form and this is what I used.
=GetDays(StartDate, EndDate)

All that comes back is blank.

What am I doing wrong?

Any help is appreciated!

Chris
 
Try

strSQL = "SELECT SUM(BR_DT.[#ofWorkDays]) AS [Days]FROM BR_DT Where (((BR_DT.[BR Date]) Between #" & Me![StartDate] & "# And #" & Me![EndDate] & "#))"
 
Rick,

I actually made this in a module so it gives me a Invalid use of Me keyword error.

Should I move this to the udnerlying code of the form?
 
How do I call it from the underlying form? I get a #Name error in my text box and if I try to run it in the debug window (With ?GetDays(04/01/2003,04/30/2003) ) then it gives me a Sub or Function not defined error.

I used Private Sub GetDays(Startdt, Enddt as Date)

And I removed the name of Getdays from the module.

Chris
 
Try something like:

Dim db as database
sim rs as recordset
Dim strSQL As String

strSQL = "SELECT SUM(BR_DT.[#ofWorkDays]) AS [Days]FROM BR_DT Where (((BR_DT.[BR Date]) Between #" & [StartDate] & "# And #" & [EndDate] & "#))"

set db = CurrentDb
Set rs = rs.openrecordset(strSQL)
rs.movefirst
Me!YourTextField = rs!Days
rs.close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top