funktion mit Recordsetfeldübergabe

J

Jörg Harnisch

Hallo NG

ich habe eine Funktion geschrieben und möchte in einem Formular einen Wert
aus einem Recordset erhalten.
Ich habe in der Tabelle die ich mit dem RS öffne verschiedene Felder und je
nach dem welches ich übergebe, möchte ich den Inhalt
zurückbekommen. Nun ist mein Problem, dass die Funktion mir einen String
erzeugt, der dann zurückgegeben wird, aber nicht der Inhalt des RS.
Bitte um Hilfe.

Function LeWertKundDet(Was)
Dim dbs2 As Database
Dim rs2 As Recordset
Set dbs2 = CurrentDb
If IsNull(Forms!KundenFor!ID) = False Then
Set rs2 = dbs2.OpenRecordset("select * from Kunden_KontaktTab where
VWert =" & Forms!KundenFor!ID & " order by EDat")
If rs2.RecordCount > 0 Then
rs2.MoveLast
Was = rs2! & Was
LeWertKundDet = Was
End If
rs2.Close
End If
Set dbs2 = Nothing
End Function

Wenn ich jetzt ein Control erstelle mit dem Inhalt =LeWertKundDet(K_Tel),
dann bekomme ich als Wert "rs2!K_Tel" zurück, aber nicht den Inhalt. Ich
hoffe, man kann mich verstehen ;)

Danke
Jörg Harnisch
 
G

Guest

Hi Jorg,
Please write your issue in english, otherwise I can't help you because I
don't understand German.
 
J

Jörg Harnisch

Hello,
sorry for my bad english

have written a function and would like to receive a value from a Recordset
in a form. I have in the table I with rs opens different fields and
according to which I hand over, I would like to get back the contents. Now
is my problem that the function to me generates a string which is returned
then, but not the contents rs.
Please help. Thx

Function LeWertKundDet(Was)
Dim dbs2 As Database
Dim rs2 As Recordset
Set dbs2 = CurrentDb
If IsNull(Forms!KundenFor!ID) = False Then
Set rs2 = dbs2.OpenRecordset("select * from Kunden_KontaktTab where
VWert =" & Forms!KundenFor!ID & " order by EDat")
If rs2.RecordCount > 0 Then
rs2.MoveLast
Was = rs2! & Was
LeWertKundDet = Was
End If
rs2.Close
End If
Set dbs2 = Nothing
End Function


If I provide a Control with the contents =LeWertKundDet (K_Tel), I agree as
a value " rs2! K_Tel " back, but not the contents.
I hope, you can understand me ;)

Jörg Harnisch
 
G

Guest

If I understand well you wannna pass to your function the name of the field
and the function returns the value contained in the recordset. Is that right?
If this is correct you can do that:

Function LeWertKundDet(Was as string) as variant
Dim rs2 As Recordset
If IsNull(Forms!KundenFor!ID) = False Then
Set rs2 = currentdb.OpenRecordset("select * from Kunden_KontaktTab
where VWert =" & Forms!KundenFor!ID & " order by EDat")
If rs2.RecordCount > 0 Then
rs2.MoveLast
LeWertKundDet = rs2(Was)
End If
rs2.Close
End If
End Function

Otherwise try to explain me better what you wanna do

HTH Paolo
 
J

Jörg Harnisch

Thank you - it works ;)

Paolo said:
If I understand well you wannna pass to your function the name of the
field
and the function returns the value contained in the recordset. Is that
right?
If this is correct you can do that:

Function LeWertKundDet(Was as string) as variant
Dim rs2 As Recordset
If IsNull(Forms!KundenFor!ID) = False Then
Set rs2 = currentdb.OpenRecordset("select * from Kunden_KontaktTab
where VWert =" & Forms!KundenFor!ID & " order by EDat")
If rs2.RecordCount > 0 Then
rs2.MoveLast
LeWertKundDet = rs2(Was)
End If
rs2.Close
End If
End Function

Otherwise try to explain me better what you wanna do

HTH Paolo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top