PDA

View Full Version : Functions



kbsudhir
06-04-2009, 09:03 AM
Hi All,

I create afunction which takes on parameter & provides one output.

But now I need the same function to provide a two outputs but will take only one parameter/input.

How to go about doing it.

Please guide.

:doh: :doh:

Regards
Sudhir

CreganTur
06-04-2009, 09:53 AM
We need more detail. What exactly are you trying to accomplish, and what is the code for the existing function?

kbsudhir
06-04-2009, 11:02 AM
I am giving 4 char code as input to the function.

The function in turn is running a query to my database & as per the code returning me the required data.


Sub Test()

dim Parnam as string

VCde = 1254

Parnam = ListName (VCde)

Msgbox Parnam

End Sub

Function ListName(Vencode As String) As String
Dim cn As ADODB.Connection, rs, rs2, rs3 As ADODB.Recordset
Dim CS As String
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=D:\Project\Data.mdb;"
'open a recordset
Set rs = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
'rs.Close
rs.Open "SELECT List.[Handler], List.[Type] FROM List WHERE (((List.VC)='" & Vencode & "')) ;", cn, adOpenStatic, adLockOptimistic

If rs.RecordCount > 0 Then
ListName = rs("Handler").Value
rs.Close
End If


End Function



I want to provide the Type also in the output.

Regards
Sudhir

CreganTur
06-04-2009, 11:23 AM
I want to provide the Type also in the output.


The Type of what? Are you referring to the data type of the returned value, or something within your table?

mdmackillop
06-04-2009, 11:30 AM
ListName = rs("Handler").Value & ":" & [type]

Not sure about the Syntax, but you can Split the output in the original sub.

kbsudhir
06-04-2009, 11:42 AM
Its rs("type").value

mdmackillop
06-04-2009, 11:48 AM
So does that suffice?

CreganTur
06-04-2009, 12:49 PM
Or you could try:
ListName = rs("Handler").Value & rs("Type").Value