A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Need help with sql and form



 
 
Thread Tools Display Modes
  #1  
Old February 27th, 2008, 02:37 AM posted to microsoft.public.access.forms
Paul
external usenet poster
 
Posts: 4
Default Need help with sql and form

I am trying to get an average from SumOfPalletCount and rs.recordCount but I
get errors no matter how I try and do this...Is there a better way to do
this?

*********What I currently have in a qrytest:***********

PARAMETERS [DaySelected] DateTime;

SELECT RecyHistory.DateRec, Sum(RecyHistory.PalletCount) AS SumOfPalletCount

FROM RecyHistory

GROUP BY RecyHistory.DateRec

HAVING
(((DatePart("w",[RecyHistory].[DateRec]))=DatePart("w",[DaySelected])));



******And Form coding:*********

Private Sub DateRec_GotFocus()

Dim qdf As DAO.QueryDef

Dim rs As DAO.Recordset

If Not IsDate(Me.DateRec) Then

MsgBox "This value must be a date!"

Me.DateRec.SetFocus

Exit Sub

End If

Set qdf = CurrentDb.QueryDefs("Qrytest")

qdf.Parameters(0) = CDate(Me.DateRec)

Set rs = qdf.OpenRecordset

If rs.EOF Then

Me.Text4 = 0

Else

Me.Text4 = SumOfPalletCount / rs.RecordCount
------Here is were I get messed up

End If

rs.Close

Set rs = Nothing

qdf.Close

Set qdf = Nothing


  #2  
Old February 27th, 2008, 10:29 PM posted to microsoft.public.access.forms
MichaelRay via AccessMonster.com
external usenet poster
 
Posts: 9
Default Need help with sql and form

What error message are you seeing?

Paul wrote:
I am trying to get an average from SumOfPalletCount and rs.recordCount but I
get errors no matter how I try and do this...Is there a better way to do
this?

*********What I currently have in a qrytest:***********

PARAMETERS [DaySelected] DateTime;

SELECT RecyHistory.DateRec, Sum(RecyHistory.PalletCount) AS SumOfPalletCount

FROM RecyHistory

GROUP BY RecyHistory.DateRec

HAVING
(((DatePart("w",[RecyHistory].[DateRec]))=DatePart("w",[DaySelected])));

******And Form coding:*********

Private Sub DateRec_GotFocus()

Dim qdf As DAO.QueryDef

Dim rs As DAO.Recordset

If Not IsDate(Me.DateRec) Then

MsgBox "This value must be a date!"

Me.DateRec.SetFocus

Exit Sub

End If

Set qdf = CurrentDb.QueryDefs("Qrytest")

qdf.Parameters(0) = CDate(Me.DateRec)

Set rs = qdf.OpenRecordset

If rs.EOF Then

Me.Text4 = 0

Else

Me.Text4 = SumOfPalletCount / rs.RecordCount
------Here is were I get messed up

End If

rs.Close

Set rs = Nothing

qdf.Close

Set qdf = Nothing


--
Message posted via http://www.accessmonster.com

  #3  
Old February 29th, 2008, 12:00 AM posted to microsoft.public.access.forms
Paul
external usenet poster
 
Posts: 4
Default Need help with sql and form

The Error is this: "Compile Error - Sub or Funtion not Defined"

I originally did not give the correct code that is causing the error. I
want to get the total from Sum(SumOfPalletTotal) and divide it from
rs.recordCount to get the average.
Thanks for your help!





"MichaelRay via AccessMonster.com" u41420@uwe wrote in message
news:8060a6f698f2b@uwe...
What error message are you seeing?

Paul wrote:
I am trying to get an average from SumOfPalletCount and rs.recordCount but
I
get errors no matter how I try and do this...Is there a better way to do
this?

*********What I currently have in a qrytest:***********

PARAMETERS [DaySelected] DateTime;

SELECT RecyHistory.DateRec, Sum(RecyHistory.PalletCount) AS
SumOfPalletCount

FROM RecyHistory

GROUP BY RecyHistory.DateRec

HAVING
(((DatePart("w",[RecyHistory].[DateRec]))=DatePart("w",[DaySelected])));

******And Form coding:*********

Private Sub DateRec_GotFocus()

Dim qdf As DAO.QueryDef

Dim rs As DAO.Recordset

If Not IsDate(Me.DateRec) Then

MsgBox "This value must be a date!"

Me.DateRec.SetFocus

Exit Sub

End If

Set qdf = CurrentDb.QueryDefs("Qrytest")

qdf.Parameters(0) = CDate(Me.DateRec)

Set rs = qdf.OpenRecordset

If rs.EOF Then

Me.Text4 = 0

Else

Me.Text4 = SumOfPalletCount / rs.RecordCount
------Here is were I get messed up

End If

rs.Close

Set rs = Nothing

qdf.Close

Set qdf = Nothing


--
Message posted via http://www.accessmonster.com



  #4  
Old February 29th, 2008, 04:32 PM posted to microsoft.public.access.forms
MichaelRay via AccessMonster.com
external usenet poster
 
Posts: 9
Default Need help with sql and form

SumOfPalletCount isn't referenced correctly. Since it is the second value
returned in the recordset, it should be referenced as rs(1), since the
recordset is zero-based. Me.Text4 = rs(1)/ rs.RecordCount should solve the
problem.


Paul wrote:
The Error is this: "Compile Error - Sub or Funtion not Defined"

I originally did not give the correct code that is causing the error. I
want to get the total from Sum(SumOfPalletTotal) and divide it from
rs.recordCount to get the average.
Thanks for your help!

What error message are you seeing?

[quoted text clipped - 59 lines]

Set qdf = Nothing


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200802/1

  #5  
Old March 4th, 2008, 01:05 AM posted to microsoft.public.access.forms
Paul
external usenet poster
 
Posts: 4
Default Need help with sql and form

Thanks for getting back to me

This is what is happening now...
DateRec SumOfPalletCount

Monday, October 29, 2007 6

Monday, November 05, 2007 4

Monday, November 26, 2007 8

Monday, December 10, 2007 9

Monday, December 17, 2007 8

Monday, January 07, 2008 7

Monday, January 14, 2008 9

Monday, January 28, 2008 6

Daterec = 8 SumOfPalletCount = 57

Me.Text4 = rs(1) / rs.RecordCount This is what I am getting for values



Me.text4 = 0.75 rs(1)=6 rs.recordCount=8



rs(1) should be the total of SumOfPalletCount

"MichaelRay via AccessMonster.com" u41420@uwe wrote in message
news:8076aeffc7b1c@uwe...
SumOfPalletCount isn't referenced correctly. Since it is the second value
returned in the recordset, it should be referenced as rs(1), since the
recordset is zero-based. Me.Text4 = rs(1)/ rs.RecordCount should solve
the
problem.


Paul wrote:
The Error is this: "Compile Error - Sub or Funtion not Defined"

I originally did not give the correct code that is causing the error. I
want to get the total from Sum(SumOfPalletTotal) and divide it from
rs.recordCount to get the average.
Thanks for your help!

What error message are you seeing?

[quoted text clipped - 59 lines]

Set qdf = Nothing


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200802/1



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:02 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.