PC Review


Reply
 
 
=?Utf-8?B?TWFya1M=?=
Guest
Posts: n/a
 
      15th Nov 2007
Hi,
I use this code to get the hours in a contracts

Set rst1 = CurrentDb.OpenRecordset("Select count(PeriodNo)/2 as hours from
IERSPROD_TOFFERSLOT Where OfferCD = '" & sOfferCD & "'")
rst1.MoveFirst
lHours = rst1(0)

there can only be one answer. Is there a way to load the hours into 'lHours'
with out using a recordset

Thanks
 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      15th Nov 2007
Perhaps:

Me.lHours = DCount("PeriodNo", "IERSPROD_TOFFERSLOT", _
"OfferCD =""" & sOfferCD & """") / 2

I doubt this will execute any more quickly than your recordset does.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MarkS" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I use this code to get the hours in a contracts
>
> Set rst1 = CurrentDb.OpenRecordset("Select count(PeriodNo)/2 as hours from
> IERSPROD_TOFFERSLOT Where OfferCD = '" & sOfferCD & "'")
> rst1.MoveFirst
> lHours = rst1(0)
>
> there can only be one answer. Is there a way to load the hours into
> 'lHours'
> with out using a recordset
>
> Thanks


 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      15th Nov 2007
In news:(E-Mail Removed),
MarkS <(E-Mail Removed)> wrote:
> Hi,
> I use this code to get the hours in a contracts
>
> Set rst1 = CurrentDb.OpenRecordset("Select count(PeriodNo)/2 as hours
> from IERSPROD_TOFFERSLOT Where OfferCD = '" & sOfferCD & "'")
> rst1.MoveFirst
> lHours = rst1(0)
>
> there can only be one answer. Is there a way to load the hours into
> 'lHours' with out using a recordset


Even if you call DLookup or DCount, there'll still be a recordset at
work; it'll just be inside the function instead of outside it. I think
you'll do better with your own recordset.

Note, though, that this line:

> rst1.MoveFirst


.... is unnecessary. When you first open a recordset, you're at the
first record already, unless the recordset is empty.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
=?Utf-8?B?TWFya1M=?=
Guest
Posts: n/a
 
      15th Nov 2007
Hi,
This answers my question. I need to the same basic thing in several places
and I want to reduce the code to a standed one line piece of code. This will
work fine

Thanks

"Dirk Goldgar" wrote:

> In news:(E-Mail Removed),
> MarkS <(E-Mail Removed)> wrote:
> > Hi,
> > I use this code to get the hours in a contracts
> >
> > Set rst1 = CurrentDb.OpenRecordset("Select count(PeriodNo)/2 as hours
> > from IERSPROD_TOFFERSLOT Where OfferCD = '" & sOfferCD & "'")
> > rst1.MoveFirst
> > lHours = rst1(0)
> >
> > there can only be one answer. Is there a way to load the hours into
> > 'lHours' with out using a recordset

>
> Even if you call DLookup or DCount, there'll still be a recordset at
> work; it'll just be inside the function instead of outside it. I think
> you'll do better with your own recordset.
>
> Note, though, that this line:
>
> > rst1.MoveFirst

>
> .... is unnecessary. When you first open a recordset, you're at the
> first record already, unless the recordset is empty.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>

 
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
It gets better and better Scribner Windows XP General 1 23rd Dec 2004 05:12 PM
Import-Text better? Excel better? KT Microsoft Access 6 28th Oct 2004 03:25 PM
I need a better way or better function than the 'IF' function =?Utf-8?B?aGF2b2NkcmFnb24=?= Microsoft Excel Worksheet Functions 10 17th Aug 2004 10:37 PM
Is InCD better than DirectCD (Drag to disk)? If it is - How is it better? Dmitriy Kopnichev Windows XP Hardware 12 13th Jan 2004 08:12 AM
Which is better (better asked) djc Microsoft Access Form Coding 3 15th Sep 2003 12:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:27 AM.