Expressin an SQL statement under DAO

  • Thread starter George Papadopoulos
  • Start date
G

George Papadopoulos

I have written the code below, for the Load of a form I am creating. The
form is being opened by another form, which passes it a long integer
parameter.

Private Sub Form_Load()

Dim dbEPEMBATHS As Database
Dim rsSpares As Recordset
Dim Kwdikos As Long
Dim objvar As Object

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

' Set dbLib to the current database
Set dbEPEMBATHS = CurrentDb

' Create a query
strselect = "Select * FROM ANTALLAKTIKA WHERE
[ANTALLAKTIKA].Kwdikos_episkeyhs = Me.OpenArgs "

[Spares_List].RowSource = strselect

End Sub

The code works, but the SQL statement returns all records of
table"ANTALLAKTIKA" instead of limited recordset by use of the WHERE clause.
How can I express this SQL statement correctly.

George Papadopoulos
 
G

Guest

George

If you don't already have it, you need to add

Dim strselect As Strin

Change the strselect line to
'-------
' Create a quer
strselect = "Select * FROM ANTALLAKTIKA WHERE [ANTALLAKTIKA].Kwdikos_episkeyhs = " & Kwdikos

'DELETE next line after testin
MsgBox strselec
'-------

The message box will allow you to see the contents of the Select string

Since you are setting the rowsource for a combo/list box (and not opening a recordset), you could shorten the code to
'----
Private Sub Form_Load(
Dim Kwdikos As Lon
Dim strselect As Strin

If Not IsNull(Me.OpenArgs) The
Kwdikos = Me.OpenArg
End I

' Create a quer
strselect = "Select * FROM ANTALLAKTIKA WHERE [ANTALLAKTIKA].Kwdikos_episkeyhs = " & Kwdikos

[Spares_List].RowSource = strselec

End Su
'----

HT

Stev
 
G

George Papadopoulos

ok. thx. everything fine. Great!


Ï "SteveS said:
George,

If you don't already have it, you need to add

Dim strselect As String


Change the strselect line to:
'--------
' Create a query
strselect = "Select * FROM ANTALLAKTIKA WHERE
[ANTALLAKTIKA].Kwdikos_episkeyhs = " & Kwdikos
'DELETE next line after testing
MsgBox strselect
'--------

The message box will allow you to see the contents of the Select string.

Since you are setting the rowsource for a combo/list box (and not opening
a recordset), you could shorten the code to:
'-----
Private Sub Form_Load()
Dim Kwdikos As Long
Dim strselect As String

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

' Create a query
strselect = "Select * FROM ANTALLAKTIKA WHERE
[ANTALLAKTIKA].Kwdikos_episkeyhs = " & Kwdikos
[Spares_List].RowSource = strselect

End Sub
'-----

HTH

Steve
 

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

Top