function error

boycie

Registered User.
Local time
Today, 22:53
Joined
Sep 19, 2001
Messages
45
Hi,

I have written the following function;

Private Function GetMaxValue(ByRef strTable As String) As Long

'gets the number of records from table which will allow us to determine how many records to add

Dim db As DAO.database
Dim rs1 As DAO.Recordset


Set db = CurrentDb()

Set rs1 = db.OpenRecordset("SELECT Max(" & strTable & ".ID) AS MaxOfID FROM" & " " & strTable & ";")

rs1.MoveFirst

GetMaxValue = rs1![MaxOfID]

MsgBox GetMaxValue

rs1.Close

Set rs1 = Nothing
Set db = Nothing

End Function

when I call the function and pass it a table name as follows;

Private Sub Command2_Click()

GetMaxValue ("t_2")

MsgBox GetMaxValue

End Sub

I get the error; 'argument not optional'. Can anyone see the problem?
It works though if the msgbox is within the function

thanks
 
You have to combine these two lines:

GetMaxValue ("t_2")

MsgBox GetMaxValue


So

MsgBox GetMaxValue("t_2")
 
And if you want to use it later on, you assign it to a variable:

Dim lngValue As Long

lngValue = GetMaxValue("t_2")

MsgBox lngValue
 
thanks Bob, i tried everything except that
 

Users who are viewing this thread

Back
Top Bottom