Update query not running

Leesha
BronzeLounger
Posts: 1488
Joined: 05 Feb 2010, 22:25

Update query not running

Post by Leesha »

Hi,

I'm using the following code that Hans gave me for another project. For some reason the update query at the beginning of the code is not running and I'm not sure why.

Thanks!
Leesha

Code: Select all

DoCmd.OpenQuery "qryUpdateAHEBGeneric"
    
    Const lngBatchSize = 80 ' labels to be printed in one go
    Dim strSQL As String
    Dim strWhere As String
    Dim dbs As DAO.Database
    Dim rst1 As DAO.Recordset
    Dim rst2 As DAO.Recordset
    Dim lngSeqNo As Long
    Dim i As Long
    Set dbs = CurrentDb
    strSQL = "DELETE * FROM tblTempGeneric"
    dbs.Execute strSQL, dbFailOnError
    strSQL = "SELECT * FROM qryAHEBGeneric ORDER BY ID, Counter"
    Set rst1 = dbs.OpenRecordset(strSQL, dbOpenForwardOnly)
    Set rst2 = dbs.OpenRecordset("tblTempGeneric", dbOpenDynaset)
    Do While Not rst1.EOF
        rst2.AddNew
        lngSeqNo = lngSeqNo + 1
        rst2!SeqNo = lngSeqNo
        For i = 0 To rst1.Fields.Count - 1
            rst2.Fields(rst1.Fields(i).Name) = rst1.Fields(i)
        Next i
        rst2.Update
        rst1.MoveNext
    Loop
    rst1.close
    Set rst1 = Nothing
    rst2.close
    Set rst2 = Nothing
    Set dbs = Nothing
    For i = 1 To lngSeqNo Step lngBatchSize
        strWhere = "SeqNo Between " & i & " And " & (i + lngBatchSize - 1)
        DoCmd.OpenReport ReportName:="rptAHEBGeneric", View:=acViewNormal, WhereCondition:=strWhere
        MsgBox "Press OK to continue.", vbInformation
    Next i

End Sub
Last edited by HansV on 17 Jan 2014, 04:22, edited 1 time in total.
Reason: to add [code]...[/code] tags

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Update query not running

Post by HansV »

Without knowing anything about qryUpdateAHEBGeneric it's impossible to say.
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1488
Joined: 05 Feb 2010, 22:25

Re: Update query not running

Post by Leesha »

Hi Hans,
Here is a stripped down version of the DB. Don't groan, this one is in 97. The format of this DB is horrid but they are so used to working in it they won't allow any changes and in the past whenever they've tried to upgrade to 2003, let alone higher there have been issues.

The issue with this piece is that the update query is not entering the plu2 info. If I run the query manually it runs and the labels show.

Thanks!
Leesha
You do not have the required permissions to view the files attached to this post.

Leesha
BronzeLounger
Posts: 1488
Joined: 05 Feb 2010, 22:25

Re: Update query not running

Post by Leesha »

Hi Hans,
Just wondering if you found anything on this.
Thanks!
Leesha

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Update query not running

Post by Rudi »

Hans should be back in the lounge by tomorrow evening. He is travelling.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

Leesha
BronzeLounger
Posts: 1488
Joined: 05 Feb 2010, 22:25

Re: Update query not running

Post by Leesha »

That is awesome news!!! Here's to a great trip for Hans!
Thanks Rudi

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Update query not running

Post by HansV »

When we start out, the table tblTempGeneric is empty, so there is nothing to update.
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1488
Joined: 05 Feb 2010, 22:25

Re: Update query not running

Post by Leesha »

Hi Hans,
I hope you had a great trip!
That was my error. The table should have had info in it. When I went back to populate that table and upload again I found the error in the update table. It was updating the wrong table! I guess I was looking at it too much trying to fix it!
Thanks,
Leesha

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Update query not running

Post by HansV »

Thanks, I had a wonderful weekend away!
Best wishes,
Hans