Syntax Error In DAO Code

  • Thread starter Thread starter George Papadopoulos
  • Start date 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
 
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
 
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
 
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
 
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
 
Back
Top