Syntax Error In DAO Code

  • Thread starter George Papadopoulos
  • Start date
G

George Papadopoulos

I have written the code below :

Private Sub Form_Load()

Dim strselect As String
Dim Kwdikos As Long
Dim dbEPEMBATHS As Database
Dim sum1 As Long

' Make a connection to the database
Set dbEPEMBATHS = CurrentDb

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

' Create a query
strselect = "Select * FROM ANTALLAKTIKA WHERE Kwdikos_episkeyhs =" &
Kwdikos

[Spares_List].RowSource = strselect

strselect = "Select Sum(Kostos) FROM ANTALLAKTIKA WHERE Kwdikos_episkeyhs
=" & Kwdikos

sum1 = dbEPEMBATHS.Execute(strselect)

End Sub

for the OnLoad event of a form I am building. The last statement fails to
compile. How can I correctly rephrase this statement? The general idea is to
fill a list_box with the results of the first query. Then I need to execute
an aggregate query under the condition shown in the code.

Any suggestions?

thx, in advance

George Papadopoulos
 
M

Michel Walsh

Hi,

WIth DAO, Execute can only be use for action query, not for query returning
data.


sum1 = dbEPEMBATHS.OpenRecordset(strselect).FIelds(0).Value


should work.



Hoping it may help,
Vanderghast, Access MVP
 
G

George Papadopoulos

thx, Michel. It worked! I now have another problem though! How can I assign
the value of sum1 to a text box on the form?

Thanks, again

George Papadopoulos

Ï "Michel Walsh said:
Hi,

WIth DAO, Execute can only be use for action query, not for query returning
data.


sum1 = dbEPEMBATHS.OpenRecordset(strselect).FIelds(0).Value


should work.



Hoping it may help,
Vanderghast, Access MVP



George Papadopoulos said:
I have written the code below :

Private Sub Form_Load()

Dim strselect As String
Dim Kwdikos As Long
Dim dbEPEMBATHS As Database
Dim sum1 As Long

' Make a connection to the database
Set dbEPEMBATHS = CurrentDb

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

' Create a query
strselect = "Select * FROM ANTALLAKTIKA WHERE Kwdikos_episkeyhs =" &
Kwdikos

[Spares_List].RowSource = strselect

strselect = "Select Sum(Kostos) FROM ANTALLAKTIKA WHERE Kwdikos_episkeyhs
=" & Kwdikos

sum1 = dbEPEMBATHS.Execute(strselect)

End Sub

for the OnLoad event of a form I am building. The last statement fails to
compile. How can I correctly rephrase this statement? The general idea
is
to
fill a list_box with the results of the first query. Then I need to execute
an aggregate query under the condition shown in the code.

Any suggestions?

thx, in advance

George Papadopoulos
 
M

Michel Walsh

Hi,



Me.ControlName.Value = Sum1


should do.



Vanderghast, Access MVP


George Papadopoulos said:
thx, Michel. It worked! I now have another problem though! How can I assign
the value of sum1 to a text box on the form?

Thanks, again

George Papadopoulos

Ï "Michel Walsh said:
Hi,

WIth DAO, Execute can only be use for action query, not for query returning
data.


sum1 = dbEPEMBATHS.OpenRecordset(strselect).FIelds(0).Value


should work.



Hoping it may help,
Vanderghast, Access MVP



George Papadopoulos said:
I have written the code below :

Private Sub Form_Load()

Dim strselect As String
Dim Kwdikos As Long
Dim dbEPEMBATHS As Database
Dim sum1 As Long

' Make a connection to the database
Set dbEPEMBATHS = CurrentDb

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

' Create a query
strselect = "Select * FROM ANTALLAKTIKA WHERE Kwdikos_episkeyhs =" &
Kwdikos

[Spares_List].RowSource = strselect

strselect = "Select Sum(Kostos) FROM ANTALLAKTIKA WHERE Kwdikos_episkeyhs
=" & Kwdikos

sum1 = dbEPEMBATHS.Execute(strselect)

End Sub

for the OnLoad event of a form I am building. The last statement fails to
compile. How can I correctly rephrase this statement? The general idea
is
to
fill a list_box with the results of the first query. Then I need to execute
an aggregate query under the condition shown in the code.

Any suggestions?

thx, in advance

George Papadopoulos
 
G

George Papadopoulos

thx, Michel. Everything worked as you said.

George Papadopoulos

Ï "Michel Walsh said:
Hi,



Me.ControlName.Value = Sum1


should do.



Vanderghast, Access MVP


George Papadopoulos said:
thx, Michel. It worked! I now have another problem though! How can I assign
the value of sum1 to a text box on the form?

Thanks, again

George Papadopoulos

Ï "Michel Walsh said:
Hi,

WIth DAO, Execute can only be use for action query, not for query returning
data.


sum1 = dbEPEMBATHS.OpenRecordset(strselect).FIelds(0).Value


should work.



Hoping it may help,
Vanderghast, Access MVP



I have written the code below :

Private Sub Form_Load()

Dim strselect As String
Dim Kwdikos As Long
Dim dbEPEMBATHS As Database
Dim sum1 As Long

' Make a connection to the database
Set dbEPEMBATHS = CurrentDb

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

' Create a query
strselect = "Select * FROM ANTALLAKTIKA WHERE Kwdikos_episkeyhs =" &
Kwdikos

[Spares_List].RowSource = strselect

strselect = "Select Sum(Kostos) FROM ANTALLAKTIKA WHERE
Kwdikos_episkeyhs
=" & Kwdikos

sum1 = dbEPEMBATHS.Execute(strselect)

End Sub

for the OnLoad event of a form I am building. The last statement
fails
to
compile. How can I correctly rephrase this statement? The general
idea
is
to
fill a list_box with the results of the first query. Then I need to
execute
an aggregate query under the condition shown in the code.

Any suggestions?

thx, in advance

George Papadopoulos
 

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