What am I doing wrong? 
Author Message
 What am I doing wrong?

Subject:
            What am I doing wrong?
       Date:
            Tue, 30 Jan 2001 10:31:17 -0500
       From:

 Newsgroups:
            microsoft.public.access.modulesdaovba.ado

Help if you can!

I've written code in Access 2000 to suck-in a lot of text files, and put

some of the info into a table.  Everything works *great* when I
step-through the code a line at a time (using the F8 key).  BUT, when I
execute it a "full speeed," and then look at my data table for the
results, some fields are blank!  If you have any ideas, I'd appreciate
them, as I am at the end of my wits.  I've tried idling the code,
thinking that it is executing too fast, but that doesn't work either.

Here's some sample code.  The purpose of the code is to look at a text
file, and output results into a table.  I've cut-out a lot of code for
this posting, but hopefully I've left enough in for someone with a clue
to spot what I'm doing wrong.  Again, it works well when
stepped-through, but not at full speed!

Dim dbs_survey As DAO.Database
Dim rst_survey_in As DAO.Recordset
Dim rst_survey_out As DAO.Recordset
Dim fld_field1_in As DAO.Field
Dim fld_field1_out As DAO.Field

Set dbs_survey = opendatabase("survey.mdb")
Set rst_survey_in = dbs_survey.OpenRecordset("tbl_survey_in")
Set rst_survey_out = dbs_survey.OpenRecordset("tbl_survey_out",
dbOpenDynaset)

rst_survey_in.MoveFirst
rst_survey_out.AddNew

Do While Not rst_survey_in.EOF
            rst_survey_out!model = Trim(Right(rst_survey_in!field1, 13))

            rst_survey_out!Serial = Trim(Right(rst_survey_in!field1,
13))
            rst_survey_out!SurveyDate = Trim(Right(rst_survey_in!field1,

20))
            DBEngine.Idle
            DBEngine.Idle dbRefreshCache
            DBEngine.Idle dbForceOSFlush
            rst_survey_in.MoveNext
Loop

DBEngine.Idle
DBEngine.Idle dbRefreshCache
DBEngine.Idle dbForceOSFlush
rst_survey_out.Update
rst_survey_in.Close
rst_survey_out.Close



Sat, 19 Jul 2003 23:35:48 GMT  
 What am I doing wrong?
Mike,

Unless this was an editing problem when you cut down your code to post
it, your code is only going to get the contents of the last record in
rst_survey_in . This would explain missing records. The Addnew and
Update commands for rst_survey_out should be inside the loop.
Something like:

rst_survey_in.MoveFirst
Do While Not rst_survey_in.EOF
        ' the "With" construct is more efficient when making multiple
        ' references to the same object
        with rst_Survey_out
            .AddNew
            !model = Trim(Right(rst_survey_in!field1, 13))
            !Serial = Trim(Right(rst_survey_in!field1, 13))
            !SurveyDate = Trim(Right(rst_survey_in!field1, 20))
            .update
        end with
        ' I doubt that you really need these statements -
        DBEngine.Idle
        DBEngine.Idle dbRefreshCache
        DBEngine.Idle dbForceOSFlush
        rst_survey_in.movenext
loop

--

Sandra Daigle, Microsoft Access MVP



Quote:
> Subject:
>             What am I doing wrong?
>        Date:
>             Tue, 30 Jan 2001 10:31:17 -0500
>        From:
>             Mike Trent


Quote:
>  Newsgroups:
>             microsoft.public.access.modulesdaovba.ado

> Help if you can!

> I've written code in Access 2000 to suck-in a lot of text files, and
put

> some of the info into a table.  Everything works *great* when I
> step-through the code a line at a time (using the F8 key).  BUT,
when I
> execute it a "full speeed," and then look at my data table for the
> results, some fields are blank!  If you have any ideas, I'd
appreciate
> them, as I am at the end of my wits.  I've tried idling the code,
> thinking that it is executing too fast, but that doesn't work
either.

> Here's some sample code.  The purpose of the code is to look at a
text
> file, and output results into a table.  I've cut-out a lot of code
for
> this posting, but hopefully I've left enough in for someone with a
clue
> to spot what I'm doing wrong.  Again, it works well when
> stepped-through, but not at full speed!

> Dim dbs_survey As DAO.Database
> Dim rst_survey_in As DAO.Recordset
> Dim rst_survey_out As DAO.Recordset
> Dim fld_field1_in As DAO.Field
> Dim fld_field1_out As DAO.Field

> Set dbs_survey = opendatabase("survey.mdb")
> Set rst_survey_in = dbs_survey.OpenRecordset("tbl_survey_in")
> Set rst_survey_out = dbs_survey.OpenRecordset("tbl_survey_out",
> dbOpenDynaset)

> rst_survey_in.MoveFirst
> rst_survey_out.AddNew

> Do While Not rst_survey_in.EOF
>             rst_survey_out!model = Trim(Right(rst_survey_in!field1,
13))
>             rst_survey_out!Serial = Trim(Right(rst_survey_in!field1,
13))
>             rst_survey_out!SurveyDate =

Trim(Right(rst_survey_in!field1, 20))

- Show quoted text -

Quote:
>             DBEngine.Idle
>             DBEngine.Idle dbRefreshCache
>             DBEngine.Idle dbForceOSFlush
>             rst_survey_in.MoveNext
> Loop

> DBEngine.Idle
> DBEngine.Idle dbRefreshCache
> DBEngine.Idle dbForceOSFlush
> rst_survey_out.Update
> rst_survey_in.Close
> rst_survey_out.Close



Sat, 19 Jul 2003 20:25:21 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Recordset: What am I doing wrong?

2. What am I doing wrong??

3. What am I doing wrong?

4. Help with syntax. What am I doing wrong

5. What am I doing wrong?

6. What am I doing wrong?

7. What am I doing wrong? -MultiSelect List box

8. Select Case - What am I doing wrong?

9. What am I doing wrong (easy).

10. OLE problem, or what am I doing wrong?

11. What am I doing wrong?

12. Footer/Page # - What am I doing wrong?

 

 
Powered by phpBB® Forum Software