Lucy Randles wrote:
[color=blue]
> Maybe if I put some of the code in you would be able to understand?
>
> My module basically does this, the call function being at the bottom...
>
> Option Compare Database
> Option Explicit
>
> Private Sub Dataextract()
> Dim strsql As String
> Dim todaydate As String
> Dim month As String
> Dim monthupper As String
> Dim year As Integer
>
> todaydate = Date
> month = VBA.Format(DateAdd("m", -12, todaydate), "mmm")
> monthupper = StrConv([month], 1)
> year = VBA.Format(DateAdd("m", -12, todaydate), "yyyy")
>
> STRSQL STUFF - DOES COMPILE
>
> CurrentDb.QueryDefs("A02 Insert All Sales").SQL = strsql
>
> Exit Sub
>
>
> End Sub
>
>
> Function callDataextract()
> Call Dataextract
> End Function
>
>
>
> Obviously I've taken out the sql script. Anyway, that runs, and runs
> fine, but the call function doesn't return anything. It obviously does
> 'something' as I don't get an error, but it doesn't run the module, as I
> want it to do.
>
> *** Sent via Developersdex
http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]
A Function returns something, a sub does not. Let's look at a function
that sums two numbers.
Dim intSum As Integer
intSum = SumIt(1,2)
msgbox intA
it will display 3
Function SumIt(int1, int2) As Integer
SumIt = int1 + int2
End Function
You can see that I declare the type of variable that will be returned.
You also see that SumIt is assigned the value of adding the two
integers. If I were to comment out the line
SumIt = int1 + int2
then the result would be zero.
Now, a subroutine does not return a value.
Dim intSum As Integer
SumIt 1,2
Sub SumIt(int1, int2)
msgbox int1 + int2
End Function
You can see I called SUmIt but nothing is returned to the calling
program. You could test this out in a module if you'd like to see the
difference.