PC Review


Reply
Thread Tools Rate Thread

Assign the records shown in a subform to a recordset

 
 
Paulo
Guest
Posts: n/a
 
      16th Feb 2010
What coulb be wrong with this code? I am trying to attribute the current
records shown in a subform to a recordset, and then performing some
calculations with the records. I am also assuming (I don't know if correctly)
that the recordset will reflect any filtering applied before to the subform
(through a combo box in the main form). This code is included in a event for
the main form. I am getting error messages.

Thanks in advance,

Paulo

====================================

Dim Total_Turnover As Single
Dim rst As DAO.Recordset
Set rst = Me.[Sub Bids Tracking].Form.Recordset
Total_Turnover = 0

With rst

.OpenRecordset
.MoveFirst

While Not rst.EOF
If rst![Channel].Value = "Wholesale" Then
If IsNull(rst![WSale Price].Value) Then
If IsNull(rst![Received Qty].Value) Then
Total_Turnover = Total_Turnover + (rst![WSale Price]
* rst![Received Qty])
End If
End If
End If
rst.MoveNext
Wend

Me.[Sub Bids Tracking].Form.Text123.Value = Totaller

rst.Close



 
Reply With Quote
 
 
 
 
Marshall Barton
Guest
Posts: n/a
 
      16th Feb 2010
Paulo wrote:

>What coulb be wrong with this code? I am trying to attribute the current
>records shown in a subform to a recordset, and then performing some
>calculations with the records. I am also assuming (I don't know if correctly)
>that the recordset will reflect any filtering applied before to the subform
>(through a combo box in the main form). This code is included in a event for
>the main form. I am getting error messages.
>
>====================================
>
> Dim Total_Turnover As Single
> Dim rst As DAO.Recordset
> Set rst = Me.[Sub Bids Tracking].Form.Recordset
> Total_Turnover = 0
>
> With rst
>
> .OpenRecordset
> .MoveFirst
>
> While Not rst.EOF
> If rst![Channel].Value = "Wholesale" Then
> If IsNull(rst![WSale Price].Value) Then
> If IsNull(rst![Received Qty].Value) Then
> Total_Turnover = Total_Turnover + (rst![WSale Price]
>* rst![Received Qty])
> End If
> End If
> End If
> rst.MoveNext
> Wend
>
> Me.[Sub Bids Tracking].Form.Text123.Value = Totaller
>
> rst.Close



Since the cakcukation will only be done when the price and
qty are Null the total will always be Null and that can not
be assinged to a single variable.

You probably want to chack for Not IsNull(...) and this kind
of calculation should use a Currency type, not Single.

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
Paulo
Guest
Posts: n/a
 
      17th Feb 2010
That's what I missed in the code. It's definitely "Not Isnull".

Thanks a lot,

Paulo



"Marshall Barton" wrote:

> Paulo wrote:
>
> >What coulb be wrong with this code? I am trying to attribute the current
> >records shown in a subform to a recordset, and then performing some
> >calculations with the records. I am also assuming (I don't know if correctly)
> >that the recordset will reflect any filtering applied before to the subform
> >(through a combo box in the main form). This code is included in a event for
> >the main form. I am getting error messages.
> >
> >====================================
> >
> > Dim Total_Turnover As Single
> > Dim rst As DAO.Recordset
> > Set rst = Me.[Sub Bids Tracking].Form.Recordset
> > Total_Turnover = 0
> >
> > With rst
> >
> > .OpenRecordset
> > .MoveFirst
> >
> > While Not rst.EOF
> > If rst![Channel].Value = "Wholesale" Then
> > If IsNull(rst![WSale Price].Value) Then
> > If IsNull(rst![Received Qty].Value) Then
> > Total_Turnover = Total_Turnover + (rst![WSale Price]
> >* rst![Received Qty])
> > End If
> > End If
> > End If
> > rst.MoveNext
> > Wend
> >
> > Me.[Sub Bids Tracking].Form.Text123.Value = Totaller
> >
> > rst.Close

>
>
> Since the cakcukation will only be done when the price and
> qty are Null the total will always be Null and that can not
> be assinged to a single variable.
>
> You probably want to chack for Not IsNull(...) and this kind
> of calculation should use a Currency type, not Single.
>
> --
> Marsh
> MVP [MS Access]
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter main form to records with no related records in subform,maintain updateable recordset esn Microsoft Access Form Coding 4 3rd Sep 2011 01:07 AM
Assign recordset - subform LisaB Microsoft Access Form Coding 1 6th Aug 2009 03:56 PM
Subform doesn show all records in recordset dle4d Microsoft Access Forms 4 29th Jan 2009 09:07 PM
Assign Recordset to Subform Help Brandon Johnson Microsoft Access Form Coding 5 20th Jun 2006 07:40 PM
Filter applied to form limits records shown on subform =?Utf-8?B?Sm9uIEwu?= Microsoft Access Form Coding 0 6th Dec 2004 07:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:52 PM.