ending msgbox results in loop (1 Viewer)

edojanssen

Registered User.
Local time
Today, 14:05
Joined
Jun 21, 2006
Messages
23
I've build an invoicingprogram for two kinds of invoices. One part generates invoicenumbers automatically. On the other part users will have to enter an invoicenumber manually (working on it to automize this too). But for the time being I have this workaround.

The problem is caused by the manual inserting of the invoicenumber. Users have to enter the number into an msgbox. If the don't want to enter an number and they click on cancel they still are asked to enter a number. What I want is that if they click on cancel the entry is canceled and no record is made.

Who can help me out?

Code:
Private Sub NwFactuur_Click()
On Error GoTo Err_NwFactuur_Click

If MsgBox("Betreft de invoer een ErBo faktuur?", vbQuestion + vbYesNo, "Type faktuur?") = vbYes Then
   
    Me.Refresh
    DoCmd.GoToRecord , , acNewRec
   
    Dim iJaarE As Integer
    Dim sJaarE As Integer
    Dim sInputE As String
   
InputBox:
    sInputE = InputBox("Geef het ErBo-boekstuknummer uit Exact op!", "ErBo-boekstuknummer")
    iJaarE = Format(Date, "yyyy")
    sJaarE = Right(CStr(iJaarE), 2)

    If sInputE Like sJaarE & "71*" Then
        If Len(sInputE) <> 8 Then
            GoTo ErrorNummer
            'GoTo InputBox
        Else
            If DCount("*", "tblFakturen", "Faktuurnr = " & sInputE & "") <> 0 Then
                MsgBox "Het ingevoerde boekstuknummer bestaat al" & vbCrLf & _
                "Kijk in Exact voor het juiste boekstuknummer"
                GoTo InputBox
            Else
                [Faktuurnr] = sInputE
                Me.ErBo.Value = True
                Me.Refresh
                DoCmd.GoToControl "Datum"
                GoTo NoErrorNummer
            End If
        End If
    Else
        GoTo ErrorNummer
    End If

NoErrorNummer:
    Exit Sub

ErrorNummer:
    MsgBox "Het ingevoerde boekstuknummer is niet juist!" & vbCrLf & _
    "Kijk in Exact voor het juiste boekstuknummer." & vbCrLf & vbCrLf & _
    "(bijv.: " & sJaarE & "710001" & ")"
    GoTo InputBox

Else
        Me.Refresh
        DoCmd.GoToRecord , , acNewRec

        If Me.NewRecord = True Then
            Dim iJaar As Integer
            Dim sJaar As Integer
            Dim iVolg As Integer
            Dim sTemp As String
            'Dim strjaartal As Integer

            iJaar = Format(Date, "yyyy")
            sJaar = Right(CStr(iJaar), 2)
            sTemp = Nz(DMax("[Faktuurnr]", "qryFakturenNietErbo", "[Faktuurnr] like '" & sJaar & "*'"))
            iVolg = Val(Right("0000" & sTemp, 4))
            iVolg = iVolg + 1
            [Faktuurnr] = Right((sJaar & Format(iVolg, "200000")), 8)
            Me.Refresh 'om faktuurnummer direct op te slaan in tabel zodat niet iemand anders zelfde nummer aan kan maken.
            DoCmd.GoToControl "Datum"
        Else
        End If
End If

Exit_NwFactuur_Click:
    Exit Sub

Err_NwFactuur_Click:
    MsgBox Err.Description
    Resume Exit_NwFactuur_Click
   
   
End Sub
 

highandwild

Registered User.
Local time
Today, 13:05
Joined
Oct 30, 2009
Messages
435
I would keep this simple and have a do while loop that iterates until
the user either enters an acceptable value or selects the Cancel button returning a zero length string. This probably uses less code.

There is no need to force the user to enter the year as a prefix, you can add this on later.

Using goto like this makes it harder to follow the flow. I like it to go from start to finish of the procedure in a sequential order with only errors forcing execution to jump to a handler.
 

Users who are viewing this thread

Top Bottom