PC Review


Reply
Thread Tools Rate Thread

dbas to access

 
 
=?Utf-8?B?bWF1a2Vu?=
Guest
Posts: n/a
 
      26th Jun 2005

I am moving from dbas to access. I have 2 tables - todays runners and past
results. identical structures. the results table may have numerous lines of
form for each of todays runners. I only want to return the most recent 4
formlines.
the following dbas.prg works ok.
select 3
use temp
select 2
use results index rname
select 1
use runners
do while .not. eof()
store name to aname
select 2
seek aname
copy next 4 to temp2 while name = aname
select 3
use temp ( new file with max of 4 formlines for any runner )
append from temp2
select 1
skip
enddo

if any one could help me achieve the same result in access i would be most
grateful
with queries I'm getting all results. with modules I don't know how
to work of 2 tables.
--
regards, maurice.
 
Reply With Quote
 
 
 
 
RuralGuy
Guest
Posts: n/a
 
      26th Jun 2005
<(E-Mail Removed)> wrote:

> I am moving from dbas to access. I have 2 tables - todays runners and
> past results. identical structures. the results table may have
> numerous lines of form for each of todays runners. I only want to
> return the most recent 4 formlines.
>
> the following dbas.prg works ok.
>
> select 3
> use temp
> select 2
> use results index rname
> select 1
> use runners
> do while .not. eof()
> store name to aname
> select 2
> seek aname
> copy next 4 to temp2 while name = aname
> select 3
> use temp
> (new file with max of 4 formlines for any runner)
> append from temp2
> select 1
> skip
> enddo
>
> if any one could help me achieve the same result in access i would be
> most grateful with queries I'm getting all results. with modules I
> don't know how to work of 2 tables.


Hi Mauken,

I think this article is what you are looking for:

http://support.microsoft.com/default...b;en-us;153747

Post back if you need additional assistance.

HTH

--
RuralGuy

Please reply to the newsgroup so all may benefit.
 
Reply With Quote
 
Albert D.Kallal
Guest
Posts: n/a
 
      27th Jun 2005
It is not clear if you are creating this temp data for reporting purposes.
If it is, then you don't need any code at all, but just build a query in the
query builder.

Further, the fact that you have runners, and past runners hints that these
two tables should in fact be one table, but with the addition of a field
that
sets if they are active. Even better would be to have a runners table, and
then a table of results for each runner (that way, only ONE instance
of the runners name would exist in the database).

Further, I notice that you are doing the relation via aname

What will happen if you have two John Smiths here? Using a text name to
build this relation, and fish up past data is a not a good idea.

As mentioned, it is not at all clear if you need this data transferred to a
temp table for reporting, or for some other needs.

Last, but not least, trying to take the exact code and logic from a non
relational system and use that SAME approach when you got a FABULOUS
relational database engine is NOT the way to go. In other words, you need to
change your approach here. A small change in your approach will eliminate
the need to write ANY of this code.

I not trying to rain on you here, but you need to start thinking in terms of
a relational system.

Further, the fact that your code grab 4 records assumes some order of data.
This could be assumed in dbaseIII etc, but it can NOT be assumed in modern
database
systems. That means if you add 4 records to a table, and then ask the data
engine to return those record,

THEY DO NOT NECESSARY COME BACK IN THE SAME
ORDER. I am not going to repeat that last statement, but read it again! It
is
a VERY important consideration when using new database systems, be they the
JET engine in ms-access, or a company wide server running oracle that order
is NOT preserved during data writes. This is conceptual change in our
industry
we had to make since products like dbase/FoxPro/clipper etc. were
popular.

So, really, using the EXACT same approach as dbase here is not so good
(however, for the sake of learning..I will post a solution in code).

Having said the above, I going to assume that you also have added a id
column (autonumber) to all your tables.

Also, looking at that dbase code, I don't see where table temp2 is cleared
after each use. I did a good stint in FoxPro for dos, but that was 13 years.
ago, so my dbase skills are a bit rusty.

And, in fact, you likely can built a query that returns the results,a nd not
use ANY code.

further, use of temp tables in ms-access is frowned upon. In dbaseIII etc,
each table is in fact a separate file. In ms-access, that table is created
in one file. This means that when you delete the table, the disk space is
not re-claimed until do a compact an repair. So, another new rule for
ms-access developers is to avoid temp tables like the plague.

So, really, we could just fire up the report builder, and build report
that gives us the results we want.

However, having said as much as is gentlemanlike like here on this
issue, lets just go ahead and write the code anyway....

we will have a table called tblRunners, tblHistory, and temp1 will wind up
with the ending data.

Sub CopyToTemp()

Dim rstRunners As DAO.Recordset
Dim strSql As String

' make our temp1 table
On Error Resume Next
CurrentDb.Execute "drop table temp1", dbFailOnError
On Error GoTo 0
CurrentDb.Execute "SELECT * INTO temp1 FROM tblRunners where id = 0;"


Set rstRunners = CurrentDb.OpenRecordset("tblRunners")

Do While rstRunners.EOF = False

strSql = "insert into temp1 " & _
"select top 4 * from tblHistory where Aname = '" & _
rstRunners!Aname & "' order by id DESC"

CurrentDb.Execute strSql

rstRunners.MoveNext
Loop

rstRunners.Close
Set rstRunners = Nothing

End Sub


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(E-Mail Removed)
http://www.members.shaw.ca/AlbertKallal


 
Reply With Quote
 
Albert D.Kallal
Guest
Posts: n/a
 
      27th Jun 2005
by the way:

strSql = "insert into temp1 " & _
"select top 4 * from tblHistory where Aname = '" & _
rstRunners!Aname & "' order by id DESC"

the above will return the last 4 history items. Your dbase code as written
returns the first 4.
So, you could drop the DESC in the above to return the first 4...

strSql = "insert into temp1 " & _
"select top 4 * from tblHistory where Aname = '" & _
rstRunners!Aname & "' order by id"


 
Reply With Quote
 
=?Utf-8?B?bWF1a2Vu?=
Guest
Posts: n/a
 
      28th Jun 2005
many thanks for your prompt reply. You are right I have to stop thinking in
dbas. the code I enclosed works ok. copy next 4 overites previous temp2 file.
temp is just a holding file. aname is a temp variable.
Your code is a bit different to anything I have written so far but I am sure
it will do what I want. So thanks again.
--
regards, maurice.


"Albert D.Kallal" wrote:

> It is not clear if you are creating this temp data for reporting purposes.
> If it is, then you don't need any code at all, but just build a query in the
> query builder.
>
> Further, the fact that you have runners, and past runners hints that these
> two tables should in fact be one table, but with the addition of a field
> that
> sets if they are active. Even better would be to have a runners table, and
> then a table of results for each runner (that way, only ONE instance
> of the runners name would exist in the database).
>
> Further, I notice that you are doing the relation via aname
>
> What will happen if you have two John Smiths here? Using a text name to
> build this relation, and fish up past data is a not a good idea.
>
> As mentioned, it is not at all clear if you need this data transferred to a
> temp table for reporting, or for some other needs.
>
> Last, but not least, trying to take the exact code and logic from a non
> relational system and use that SAME approach when you got a FABULOUS
> relational database engine is NOT the way to go. In other words, you need to
> change your approach here. A small change in your approach will eliminate
> the need to write ANY of this code.
>
> I not trying to rain on you here, but you need to start thinking in terms of
> a relational system.
>
> Further, the fact that your code grab 4 records assumes some order of data.
> This could be assumed in dbaseIII etc, but it can NOT be assumed in modern
> database
> systems. That means if you add 4 records to a table, and then ask the data
> engine to return those record,
>
> THEY DO NOT NECESSARY COME BACK IN THE SAME
> ORDER. I am not going to repeat that last statement, but read it again! It
> is
> a VERY important consideration when using new database systems, be they the
> JET engine in ms-access, or a company wide server running oracle that order
> is NOT preserved during data writes. This is conceptual change in our
> industry
> we had to make since products like dbase/FoxPro/clipper etc. were
> popular.
>
> So, really, using the EXACT same approach as dbase here is not so good
> (however, for the sake of learning..I will post a solution in code).
>
> Having said the above, I going to assume that you also have added a id
> column (autonumber) to all your tables.
>
> Also, looking at that dbase code, I don't see where table temp2 is cleared
> after each use. I did a good stint in FoxPro for dos, but that was 13 years.
> ago, so my dbase skills are a bit rusty.
>
> And, in fact, you likely can built a query that returns the results,a nd not
> use ANY code.
>
> further, use of temp tables in ms-access is frowned upon. In dbaseIII etc,
> each table is in fact a separate file. In ms-access, that table is created
> in one file. This means that when you delete the table, the disk space is
> not re-claimed until do a compact an repair. So, another new rule for
> ms-access developers is to avoid temp tables like the plague.
>
> So, really, we could just fire up the report builder, and build report
> that gives us the results we want.
>
> However, having said as much as is gentlemanlike like here on this
> issue, lets just go ahead and write the code anyway....
>
> we will have a table called tblRunners, tblHistory, and temp1 will wind up
> with the ending data.
>
> Sub CopyToTemp()
>
> Dim rstRunners As DAO.Recordset
> Dim strSql As String
>
> ' make our temp1 table
> On Error Resume Next
> CurrentDb.Execute "drop table temp1", dbFailOnError
> On Error GoTo 0
> CurrentDb.Execute "SELECT * INTO temp1 FROM tblRunners where id = 0;"
>
>
> Set rstRunners = CurrentDb.OpenRecordset("tblRunners")
>
> Do While rstRunners.EOF = False
>
> strSql = "insert into temp1 " & _
> "select top 4 * from tblHistory where Aname = '" & _
> rstRunners!Aname & "' order by id DESC"
>
> CurrentDb.Execute strSql
>
> rstRunners.MoveNext
> Loop
>
> rstRunners.Close
> Set rstRunners = Nothing
>
> End Sub
>
>
> --
> Albert D. Kallal (Access MVP)
> Edmonton, Alberta Canada
> (E-Mail Removed)
> http://www.members.shaw.ca/AlbertKallal
>
>
>

 
Reply With Quote
 
=?Utf-8?B?bWF1a2Vu?=
Guest
Posts: n/a
 
      28th Jun 2005
many thanks for pointing me to the article that solves my problem
--
regards, maurice.


"RuralGuy" wrote:

> <(E-Mail Removed)> wrote:
>
> > I am moving from dbas to access. I have 2 tables - todays runners and
> > past results. identical structures. the results table may have
> > numerous lines of form for each of todays runners. I only want to
> > return the most recent 4 formlines.
> >
> > the following dbas.prg works ok.
> >
> > select 3
> > use temp
> > select 2
> > use results index rname
> > select 1
> > use runners
> > do while .not. eof()
> > store name to aname
> > select 2
> > seek aname
> > copy next 4 to temp2 while name = aname
> > select 3
> > use temp
> > (new file with max of 4 formlines for any runner)
> > append from temp2
> > select 1
> > skip
> > enddo
> >
> > if any one could help me achieve the same result in access i would be
> > most grateful with queries I'm getting all results. with modules I
> > don't know how to work of 2 tables.

>
> Hi Mauken,
>
> I think this article is what you are looking for:
>
> http://support.microsoft.com/default...b;en-us;153747
>
> Post back if you need additional assistance.
>
> HTH
>
> --
> RuralGuy
>
> Please reply to the newsgroup so all may benefit.
>

 
Reply With Quote
 
RuralGuy
Guest
Posts: n/a
 
      28th Jun 2005
<(E-Mail Removed)> wrote:

> many thanks for pointing me to the article that solves my problem


You're very welcome. Thanks for posting back and good luck with your
project.

--
RuralGuy

Please reply to the newsgroup so all may benefit.
 
Reply With Quote
 
=?Utf-8?B?bWF1a2Vu?=
Guest
Posts: n/a
 
      13th Jul 2005
the code you gave me to get the four most recent records for any horse works
perfect except when the name includes an apostophy, then it reports syntax
error, missing operator, a few names include 2 apostophies - gone'n'dunnit
for examply.
I hope there is an easy fix.
--
regards, maurice.


"Albert D.Kallal" wrote:

> by the way:
>
> strSql = "insert into temp1 " & _
> "select top 4 * from tblHistory where Aname = '" & _
> rstRunners!Aname & "' order by id DESC"
>
> the above will return the last 4 history items. Your dbase code as written
> returns the first 4.
> So, you could drop the DESC in the above to return the first 4...
>
> strSql = "insert into temp1 " & _
> "select top 4 * from tblHistory where Aname = '" & _
> rstRunners!Aname & "' order by id"
>
>
>

 
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
Can't open my Access files after conversion from Access 97 to Access 2003 M Shafaat Microsoft Access 5 10th Apr 2010 09:04 PM
Saving Access 2007 database in Access 2003 format fails in Access =?Utf-8?B?U3Bpcm8=?= Microsoft Access External Data 0 13th Aug 2006 08:37 AM
W2K3 Service w/ UNC Access, Local Disk Access, and DB Access Rob Microsoft C# .NET 6 2nd Aug 2004 01:44 PM
Access "showing images on first page only of very wide Access report. Windows XP, Access XP Jack Microsoft Access Reports 4 18th Nov 2003 03:01 PM
Re: Allowing users (w/o MS Access) to access an Access 2000 database Wayne Morgan Microsoft Access 0 29th Sep 2003 11:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:02 AM.