Solved

gosub no sub on return

Posted on 2014-02-25
6
283 Views
Last Modified: 2014-02-25
I have code that needs to repeat the same task, so I thought I would try a GoSub/Return code, however when I am looping thru a recordset that calls the gosub it seems to get no Return found when it gets to the last record in the recordset.

what am I missing?

            Select Case MsgBox("Sorry unable to process request until Unpublished Invoice(s) have been processed/printed." _
                & vbCrLf & "" _
                & vbCrLf & "Do you wish to print UnPublished Invoices?" _
                , vbOK Or vbCritical Or vbDefaultButton1, "Invoice Needs to be Printed")
            Case vbOK
                rs.MoveFirst
                gInvID = rs.Fields("IDinvoice")
                    Do Until rs.EOF
                        GoSub MyPrint
                        rs.MoveNext
                    Loop
            Case vbCancel
                DoCmd.RunCommand acCmdUndo
                
            End Select
            
        End If
    End If
    
MyPrint:

        DoCmd.OpenReport "rptAPCodingSlip", acViewNormal, "IDInvoice = " & Chr(39) & gInvID & Chr(39) & ""
        DoCmd.OpenReport "rptInvoiceActivity_Slip", acViewNormal, "ContractNo = " & Chr(34) & gContractID & Chr(34) & ""
        DoCmd.RunSQL "Update tblinvoice Set RecordLock = -1 where IDInvoice = " & gInvID & ""

Return

End Sub

Open in new window

0
Comment
Question by:Karen Schaefer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 36

Expert Comment

by:PatHartman
ID: 39887174
   End If
 Exit Sub   
MyPrint:

Open in new window


You need an Exit Sub in front of MyPrint otherwise you just fall into that code when the loop ends.
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 39887184
Why a GoSub?

Couldn't you just put the 3 lines of code where the GoSub is?
  Case vbOK
                rs.MoveFirst
                gInvID = rs.Fields("IDinvoice")
                    Do Until rs.EOF
                         DoCmd.OpenReport "rptAPCodingSlip", acViewNormal, "IDInvoice = " & Chr(39) & gInvID & Chr(39) & ""
                        DoCmd.OpenReport "rptInvoiceActivity_Slip", acViewNormal, "ContractNo = " & Chr(34) & gContractID & Chr(34) & ""
                        DoCmd.RunSQL "Update tblinvoice Set RecordLock = -1 where IDInvoice = " & gInvID & ""
                        rs.MoveNext
                    Loop

Open in new window

0
 

Author Comment

by:Karen Schaefer
ID: 39887224
thats what I ended up doing I was trying to be more streamlined since I use those 3 lines of code multiple times within the entire code.

Thanks for the input.

K
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Closing Comment

by:Karen Schaefer
ID: 39887227
tkx
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 39887362
So, you really didn't want to know what was wrong with the original code?

The use of GoSubs lets you streamline the logic flow so it isn't bogged down in details.  It is also useful if you need to use the code in multiple situations.  I would never embed the code if I had to use it multiple times as you said you did so I completely disagree with your decision to accept imnorie's work around.
0
 
LVL 33

Expert Comment

by:Norie
ID: 39887514
If you are going to repeat those lines of code and you don't want to embed them you could put them in a separate sub/function and call that, passing any required parameters/arguments.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question