DSUM with BETWEEN statement

L

Lorenzo

Hello,
I am struggling with this DSUM function in the following case:
I am trying to get the total amount for the [intImporto] in the reservation
table and display it in a text box using some parameters. In my form I have
a cboBox to select the apartment on which I want to base my query and two
text boxes to select the timespan I want to diaplay the sales for. All
works as expected as far as displaying the total for a certain apartment but
I get errors when I add the date parameters, this is what I have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND [dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]", "tblPrenotazioni", strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what am I doing
wrong the query seems correct...
Lorenzo
 
D

Douglas J. Steele

Date values need to be delimited with # characters. As well, they need to be
in mm/dd/yyyy format, regardless of what your Regional Settings may be.
(Okay, this isn't strictly true. They can be in any unambiguous format, such
as yyyy-mm-dd or dd mmm yyyy. The point is, they cannot be dd/mm/yyyy
format.)

Try:

strSQL = "[IDImmobile]= " & Me.cboImmobile & _
" AND [dteArrivo] BETWEEN " & _
Format(dteInizio, "\#mm\/dd\/yyyy\#") & " AND " & _
Format(dteFine, "\#mm\/dd\/yyyy\#")


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Lorenzo"
 
G

Guest

In addition to what Douglas suggests, there is an error in your Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant, not a date.
Variables do not take on the type specified at the end of a line. Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date
 
D

Douglas J. Steele

True, but the code will work without making that correction.

The Date data type didn't actually get introduced until Access 95 (I
believe). In Access 2, you had to use Variants for dates.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
In addition to what Douglas suggests, there is an error in your Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant, not a date.
Variables do not take on the type specified at the end of a line. Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date

Lorenzo said:
Hello,
I am struggling with this DSUM function in the following case:
I am trying to get the total amount for the [intImporto] in the
reservation
table and display it in a text box using some parameters. In my form I
have
a cboBox to select the apartment on which I want to base my query and two
text boxes to select the timespan I want to diaplay the sales for. All
works as expected as far as displaying the total for a certain apartment
but
I get errors when I add the date parameters, this is what I have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND [dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]", "tblPrenotazioni",
strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what am I doing
wrong the query seems correct...
Lorenzo
 
G

Guest

I am aware of that; however, I am sure you will agree that it is just good
practice to correctly type your varialbes. In this case, it would not cause
a problem, but in others, it would. I believe the OP should be aware of
that. Perhaps error was the wrong word.

I only go back to 97, so I wouldn't know about earlier versions. (Guess that
makes me a newbie :)

Douglas J. Steele said:
True, but the code will work without making that correction.

The Date data type didn't actually get introduced until Access 95 (I
believe). In Access 2, you had to use Variants for dates.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
In addition to what Douglas suggests, there is an error in your Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant, not a date.
Variables do not take on the type specified at the end of a line. Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date

Lorenzo said:
Hello,
I am struggling with this DSUM function in the following case:
I am trying to get the total amount for the [intImporto] in the
reservation
table and display it in a text box using some parameters. In my form I
have
a cboBox to select the apartment on which I want to base my query and two
text boxes to select the timespan I want to diaplay the sales for. All
works as expected as far as displaying the total for a certain apartment
but
I get errors when I add the date parameters, this is what I have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND [dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]", "tblPrenotazioni",
strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what am I doing
wrong the query seems correct...
Lorenzo
 
D

Douglas J. Steele

Definitely. (you figure out to which comment I'm referring! <g>)

I don't know whether you've seen how I usually address that issue. Something
along the lines of "BTW, your declaration isn't doing what I suspect you
think it is..."

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
I am aware of that; however, I am sure you will agree that it is just good
practice to correctly type your varialbes. In this case, it would not
cause
a problem, but in others, it would. I believe the OP should be aware of
that. Perhaps error was the wrong word.

I only go back to 97, so I wouldn't know about earlier versions. (Guess
that
makes me a newbie :)

Douglas J. Steele said:
True, but the code will work without making that correction.

The Date data type didn't actually get introduced until Access 95 (I
believe). In Access 2, you had to use Variants for dates.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
In addition to what Douglas suggests, there is an error in your Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant, not a date.
Variables do not take on the type specified at the end of a line. Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date

:

Hello,
I am struggling with this DSUM function in the following case:
I am trying to get the total amount for the [intImporto] in the
reservation
table and display it in a text box using some parameters. In my form
I
have
a cboBox to select the apartment on which I want to base my query and
two
text boxes to select the timespan I want to diaplay the sales for.
All
works as expected as far as displaying the total for a certain
apartment
but
I get errors when I add the date parameters, this is what I have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND [dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]", "tblPrenotazioni",
strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what am I
doing
wrong the query seems correct...
Lorenzo
 
G

Guest

So WHAT THE #@@#$%r WHERE YOU THINKING MORON ????!!!!

Is not an appropriate response? :)

Douglas J. Steele said:
Definitely. (you figure out to which comment I'm referring! <g>)

I don't know whether you've seen how I usually address that issue. Something
along the lines of "BTW, your declaration isn't doing what I suspect you
think it is..."

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
I am aware of that; however, I am sure you will agree that it is just good
practice to correctly type your varialbes. In this case, it would not
cause
a problem, but in others, it would. I believe the OP should be aware of
that. Perhaps error was the wrong word.

I only go back to 97, so I wouldn't know about earlier versions. (Guess
that
makes me a newbie :)

Douglas J. Steele said:
True, but the code will work without making that correction.

The Date data type didn't actually get introduced until Access 95 (I
believe). In Access 2, you had to use Variants for dates.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


In addition to what Douglas suggests, there is an error in your Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant, not a date.
Variables do not take on the type specified at the end of a line. Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date

:

Hello,
I am struggling with this DSUM function in the following case:
I am trying to get the total amount for the [intImporto] in the
reservation
table and display it in a text box using some parameters. In my form
I
have
a cboBox to select the apartment on which I want to base my query and
two
text boxes to select the timespan I want to diaplay the sales for.
All
works as expected as far as displaying the total for a certain
apartment
but
I get errors when I add the date parameters, this is what I have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND [dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]", "tblPrenotazioni",
strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what am I
doing
wrong the query seems correct...
Lorenzo
 
D

Douglas J. Steele

It is to certain posters!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
So WHAT THE #@@#$%r WHERE YOU THINKING MORON ????!!!!

Is not an appropriate response? :)

Douglas J. Steele said:
Definitely. (you figure out to which comment I'm referring! <g>)

I don't know whether you've seen how I usually address that issue.
Something
along the lines of "BTW, your declaration isn't doing what I suspect you
think it is..."

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
I am aware of that; however, I am sure you will agree that it is just
good
practice to correctly type your varialbes. In this case, it would not
cause
a problem, but in others, it would. I believe the OP should be aware
of
that. Perhaps error was the wrong word.

I only go back to 97, so I wouldn't know about earlier versions. (Guess
that
makes me a newbie :)

:

True, but the code will work without making that correction.

The Date data type didn't actually get introduced until Access 95 (I
believe). In Access 2, you had to use Variants for dates.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


In addition to what Douglas suggests, there is an error in your Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant, not a
date.
Variables do not take on the type specified at the end of a line.
Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date

:

Hello,
I am struggling with this DSUM function in the following case:
I am trying to get the total amount for the [intImporto] in the
reservation
table and display it in a text box using some parameters. In my
form
I
have
a cboBox to select the apartment on which I want to base my query
and
two
text boxes to select the timespan I want to diaplay the sales for.
All
works as expected as far as displaying the total for a certain
apartment
but
I get errors when I add the date parameters, this is what I have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND
[dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]", "tblPrenotazioni",
strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what am I
doing
wrong the query seems correct...
Lorenzo
 
G

Guest

You are, as always, absolutely correct.

Douglas J. Steele said:
It is to certain posters!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
So WHAT THE #@@#$%r WHERE YOU THINKING MORON ????!!!!

Is not an appropriate response? :)

Douglas J. Steele said:
Definitely. (you figure out to which comment I'm referring! <g>)

I don't know whether you've seen how I usually address that issue.
Something
along the lines of "BTW, your declaration isn't doing what I suspect you
think it is..."

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am aware of that; however, I am sure you will agree that it is just
good
practice to correctly type your varialbes. In this case, it would not
cause
a problem, but in others, it would. I believe the OP should be aware
of
that. Perhaps error was the wrong word.

I only go back to 97, so I wouldn't know about earlier versions. (Guess
that
makes me a newbie :)

:

True, but the code will work without making that correction.

The Date data type didn't actually get introduced until Access 95 (I
believe). In Access 2, you had to use Variants for dates.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


In addition to what Douglas suggests, there is an error in your Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant, not a
date.
Variables do not take on the type specified at the end of a line.
Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date

:

Hello,
I am struggling with this DSUM function in the following case:
I am trying to get the total amount for the [intImporto] in the
reservation
table and display it in a text box using some parameters. In my
form
I
have
a cboBox to select the apartment on which I want to base my query
and
two
text boxes to select the timespan I want to diaplay the sales for.
All
works as expected as far as displaying the total for a certain
apartment
but
I get errors when I add the date parameters, this is what I have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND
[dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]", "tblPrenotazioni",
strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what am I
doing
wrong the query seems correct...
Lorenzo
 
L

Lorenzo

Hey Guys I didn't mean to start such a thread :) Well thanks for the
suggestion about the variable declaration, the code was though working
correctly...
I thought you could use Dim pippo, pluto as String so maybe was the same for
dates ! No :) ? Hey but don't fight ok!

Thanks to both
L.

Klatuu said:
You are, as always, absolutely correct.

Douglas J. Steele said:
It is to certain posters!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
So WHAT THE #@@#$%r WHERE YOU THINKING MORON ????!!!!

Is not an appropriate response? :)

:

Definitely. (you figure out to which comment I'm referring! <g>)

I don't know whether you've seen how I usually address that issue.
Something
along the lines of "BTW, your declaration isn't doing what I suspect
you
think it is..."

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am aware of that; however, I am sure you will agree that it is just
good
practice to correctly type your varialbes. In this case, it would
not
cause
a problem, but in others, it would. I believe the OP should be
aware
of
that. Perhaps error was the wrong word.

I only go back to 97, so I wouldn't know about earlier versions.
(Guess
that
makes me a newbie :)

:

True, but the code will work without making that correction.

The Date data type didn't actually get introduced until Access 95
(I
believe). In Access 2, you had to use Variants for dates.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


In addition to what Douglas suggests, there is an error in your
Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant, not a
date.
Variables do not take on the type specified at the end of a line.
Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date

:

Hello,
I am struggling with this DSUM function in the following case:
I am trying to get the total amount for the [intImporto] in the
reservation
table and display it in a text box using some parameters. In my
form
I
have
a cboBox to select the apartment on which I want to base my
query
and
two
text boxes to select the timespan I want to diaplay the sales
for.
All
works as expected as far as displaying the total for a certain
apartment
but
I get errors when I add the date parameters, this is what I
have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND
[dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]",
"tblPrenotazioni",
strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what am
I
doing
wrong the query seems correct...
Lorenzo
 
D

Douglas J. Steele

No, Dim pippo, pluto As String declares pluto as a string, and pippo as a
variant. To declare them both as strings, you must use Dim pippo As String,
pluto As String.

You cannot "short circuit" declarations in VBA. If there isn't an AS <type>
after the variable name, it's a variant.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Lorenzo"
Hey Guys I didn't mean to start such a thread :) Well thanks for the
suggestion about the variable declaration, the code was though working
correctly...
I thought you could use Dim pippo, pluto as String so maybe was the same
for dates ! No :) ? Hey but don't fight ok!

Thanks to both
L.

Klatuu said:
You are, as always, absolutely correct.

Douglas J. Steele said:
It is to certain posters!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


So WHAT THE #@@#$%r WHERE YOU THINKING MORON ????!!!!

Is not an appropriate response? :)

:

Definitely. (you figure out to which comment I'm referring! <g>)

I don't know whether you've seen how I usually address that issue.
Something
along the lines of "BTW, your declaration isn't doing what I suspect
you
think it is..."

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am aware of that; however, I am sure you will agree that it is
just
good
practice to correctly type your varialbes. In this case, it would
not
cause
a problem, but in others, it would. I believe the OP should be
aware
of
that. Perhaps error was the wrong word.

I only go back to 97, so I wouldn't know about earlier versions.
(Guess
that
makes me a newbie :)

:

True, but the code will work without making that correction.

The Date data type didn't actually get introduced until Access 95
(I
believe). In Access 2, you had to use Variants for dates.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


In addition to what Douglas suggests, there is an error in your
Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant, not
a
date.
Variables do not take on the type specified at the end of a
line.
Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date

:

Hello,
I am struggling with this DSUM function in the following case:
I am trying to get the total amount for the [intImporto] in the
reservation
table and display it in a text box using some parameters. In
my
form
I
have
a cboBox to select the apartment on which I want to base my
query
and
two
text boxes to select the timespan I want to diaplay the sales
for.
All
works as expected as far as displaying the total for a certain
apartment
but
I get errors when I add the date parameters, this is what I
have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND
[dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]",
"tblPrenotazioni",
strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what am
I
doing
wrong the query seems correct...
Lorenzo
 
G

Guest

There is not fight here, Lorenzo - only sharing info.
IMHO Douglas J Steele is one of the most knowledgeable MVPs posting to this
site. I actually appreciate it when he points out my misstatements, I learn
from him - a lot.

If you catch my posts from time to time, you will proably figure out I am a
bit of a nut case :) I am seldom rude to anyone, but I do poke fun
frequently.

Lorenzo said:
Hey Guys I didn't mean to start such a thread :) Well thanks for the
suggestion about the variable declaration, the code was though working
correctly...
I thought you could use Dim pippo, pluto as String so maybe was the same for
dates ! No :) ? Hey but don't fight ok!

Thanks to both
L.

Klatuu said:
You are, as always, absolutely correct.

Douglas J. Steele said:
It is to certain posters!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


So WHAT THE #@@#$%r WHERE YOU THINKING MORON ????!!!!

Is not an appropriate response? :)

:

Definitely. (you figure out to which comment I'm referring! <g>)

I don't know whether you've seen how I usually address that issue.
Something
along the lines of "BTW, your declaration isn't doing what I suspect
you
think it is..."

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am aware of that; however, I am sure you will agree that it is just
good
practice to correctly type your varialbes. In this case, it would
not
cause
a problem, but in others, it would. I believe the OP should be
aware
of
that. Perhaps error was the wrong word.

I only go back to 97, so I wouldn't know about earlier versions.
(Guess
that
makes me a newbie :)

:

True, but the code will work without making that correction.

The Date data type didn't actually get introduced until Access 95
(I
believe). In Access 2, you had to use Variants for dates.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


In addition to what Douglas suggests, there is an error in your
Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant, not a
date.
Variables do not take on the type specified at the end of a line.
Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date

:

Hello,
I am struggling with this DSUM function in the following case:
I am trying to get the total amount for the [intImporto] in the
reservation
table and display it in a text box using some parameters. In my
form
I
have
a cboBox to select the apartment on which I want to base my
query
and
two
text boxes to select the timespan I want to diaplay the sales
for.
All
works as expected as far as displaying the total for a certain
apartment
but
I get errors when I add the date parameters, this is what I
have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND
[dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]",
"tblPrenotazioni",
strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what am
I
doing
wrong the query seems correct...
Lorenzo
 
L

Lorenzo

I know, I got that right :) I thank you both for your precious help!

L.
Klatuu said:
There is not fight here, Lorenzo - only sharing info.
IMHO Douglas J Steele is one of the most knowledgeable MVPs posting to
this
site. I actually appreciate it when he points out my misstatements, I
learn
from him - a lot.

If you catch my posts from time to time, you will proably figure out I am
a
bit of a nut case :) I am seldom rude to anyone, but I do poke fun
frequently.

Lorenzo said:
Hey Guys I didn't mean to start such a thread :) Well thanks for the
suggestion about the variable declaration, the code was though working
correctly...
I thought you could use Dim pippo, pluto as String so maybe was the same
for
dates ! No :) ? Hey but don't fight ok!

Thanks to both
L.

Klatuu said:
You are, as always, absolutely correct.

:

It is to certain posters!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


So WHAT THE #@@#$%r WHERE YOU THINKING MORON ????!!!!

Is not an appropriate response? :)

:

Definitely. (you figure out to which comment I'm referring! <g>)

I don't know whether you've seen how I usually address that issue.
Something
along the lines of "BTW, your declaration isn't doing what I
suspect
you
think it is..."

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am aware of that; however, I am sure you will agree that it is
just
good
practice to correctly type your varialbes. In this case, it
would
not
cause
a problem, but in others, it would. I believe the OP should be
aware
of
that. Perhaps error was the wrong word.

I only go back to 97, so I wouldn't know about earlier versions.
(Guess
that
makes me a newbie :)

:

True, but the code will work without making that correction.

The Date data type didn't actually get introduced until Access
95
(I
believe). In Access 2, you had to use Variants for dates.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


In addition to what Douglas suggests, there is an error in
your
Dim.
Dim dteInizio, dteFine As Date
The way you have it coded, dteInizio is actually a Variant,
not a
date.
Variables do not take on the type specified at the end of a
line.
Each
variable has to be typed independently. It should be
Dim dteInizio as Date, dteFine As Date

:

Hello,
I am struggling with this DSUM function in the following
case:
I am trying to get the total amount for the [intImporto] in
the
reservation
table and display it in a text box using some parameters. In
my
form
I
have
a cboBox to select the apartment on which I want to base my
query
and
two
text boxes to select the timespan I want to diaplay the sales
for.
All
works as expected as far as displaying the total for a
certain
apartment
but
I get errors when I add the date parameters, this is what I
have:

Private Sub cmdVisualizza_Click()
On Error GoTo Err_cmdVisualizza_Click

Dim strSQL As String
Dim dteInizio, dteFine As Date
dteInizio = Me.dteInizio
dteFine = Me.dteFine
strSQL = "[IDImmobile]= " & Me.cboImmobile & " AND
[dteArrivo]
Between " & dteInizio & " and " & dteFine

Me.txtRisultato.Locked = False
Me.txtRisultato.Enabled = True
Me.txtRisultato.SetFocus
Me.txtRisultato.Text = DSum("[intImporto]",
"tblPrenotazioni",
strSQL)
Me.cmdVisualizza.SetFocus
Me.txtRisultato.Locked = True
Me.txtRisultato.Enabled = False

Exit_cmdVisualizza_Click:
Exit Sub

Err_cmdVisualizza_Click:
msgBox Err.Description
Resume Exit_cmdVisualizza_Click
End Sub


I get an operator missing in my msgBox warning ERR 3075 what
am
I
doing
wrong the query seems correct...
Lorenzo
 
Top