Accessing fields of record using DAO

  • Thread starter Thread starter George Papadopoulos
  • Start date Start date
G

George Papadopoulos

Hello everybody

I need to write code which will enable to access the specific fields of a
record. Specifically I`m using a Select query to pinpoint a single record.
Then I would like to access every field of that record. The code I`ve
written is :

Private Sub Form_Load()
Dim strSelect As String
Dim db As Database
Dim rsEpiskeyes As Recordset

If Not IsNull(Me.OpenArgs) Then
Me.Kwdikos_episkeyhs = Me.OpenArgs
End If

strSelect = "Select Kwdikos_texnikou, Kwdikos_mhxanhmatos,
Kwdikos_klinikhs, Hmeromhnia, Wra_enarjhs, Wra_lhjhs, Aitia_blabhs,
Katastash, Ek8esh_texnikou From EPISKEYH WHERE " & Kwdikos_episkeyhs & "=
Me.Kwdikos_episkeyhs"

' Open a connection to current database
Set db = CurrentDb()

' Open recordset satisfying criteria
Set rsEpiskeyes = db.OpenRecordset(strSelect)

End Sub

Firsty, the statement Set rsEpiskeyes = db.OpenRecordset(strSelect) fails.
Secondly, how can I access the fields of the first record in the recordset,
supposing the statement executes correctly (no syntax error).

thx, in advance

George Papadopoulos
 
Define your Database and Recordset as
DAO.Database and DAO.Recordset
and your OpenRecordset command should work.

You can refer to fields in your recordset in general by
using RS(Field) -- rsEpiskeyes(klinikhs)
 
unfortunately, that didn`t work. I`m experiencing a run-time error after
all. Specifically when the execution flow reaches the statement Set
rsEpiskeyes = db.OpenRecordset
I get the error 'Too few parameters - Expected 1'.

Any clue?
 
George said:
I need to write code which will enable to access the specific fields of a
record. Specifically I`m using a Select query to pinpoint a single record.
Then I would like to access every field of that record. The code I`ve
written is :

Private Sub Form_Load()
Dim strSelect As String
Dim db As Database
Dim rsEpiskeyes As Recordset

If Not IsNull(Me.OpenArgs) Then
Me.Kwdikos_episkeyhs = Me.OpenArgs
End If

strSelect = "Select Kwdikos_texnikou, Kwdikos_mhxanhmatos,
Kwdikos_klinikhs, Hmeromhnia, Wra_enarjhs, Wra_lhjhs, Aitia_blabhs,
Katastash, Ek8esh_texnikou From EPISKEYH WHERE " & Kwdikos_episkeyhs & "=
Me.Kwdikos_episkeyhs"


Your syntax is mixed up. If Kwdikos_episkeyhs is a numeric
field, try this:

WHERE Kwdikos_episkeyhs =" & Me.Kwdikos_episkeyhs

If it's a Text field:

WHERE Kwdikos_episkeyhs =""" & Me.Kwdikos_episkeyhs & """"
 
Back
Top