Results 1 to 9 of 9
  1. #1
    AccessNewM is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    4

    Help needed for correcting code for creation of new bills

    Hi everybody,

    hope you could help me out.

    We have to use new bills from the next months on which we want our access programm to take over automatically.
    So until the ende of june 2020 itīs fine to go with the bill fromat "rechnungdauer2016".
    From July on we have to use the bill format "rechnungdauer2020".

    With the code below you find my edited code. What did I do wrong that the edited code does not work?

    Below that you find the (still working) original old code which included only the "rechnungdauer2016" (and not the new "rechnungdauer2020") bill format and the older formats "rechnung2006" and "rechnung2007" which are not used anymore (this is why I left them out in the new code).


    Thank you so much for your help and advice.

    I appreciate it a lot.

    Your AccessNewM (absolute beginner in programming)


    ************************************************** *****
    NEW edited code (not working)

    Private Function CreateRechnung() As String

    On Error GoTo Err_CreateRechnung

    If Me.Dirty Then
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    End If

    Dim stDocName As String
    Dim daRechDatum As Date
    Dim daSplitDatum As Date
    Dim filename As String



    filename = Environ("temp") + "\Rechnungsbeispiel.pdf"

    daSplitDatum = "01.07.2020"

    If Not IsNull(Me.RDatum.value) And Not IsNull(Me.Art) Then

    daRechDatum = Me.RDatum.value
    If Me.RechnungsZyklus = "Dauerrechnung" Then
    Select Case Me.Art
    Case "E"
    If daRechDatum < daSplitDatum Then
    stDocName = "RechnungDauer2016"
    Else
    stDocName = "RechnungDauer2020"


    End If
    Case "M"
    If daRechDatum < daSplitDatum Then
    stDocName = "RechnungDauer2016"
    Else
    stDocName = "RechnungDauer2020"
    End If

    Call Monate 'Aktion

    If Me.RZeitraumMonate < 1 Then
    MsgBox "RZeitraum Monate kleiner 1!"
    Exit Function
    End If
    End Select

    End If

    ************************************************** **********


    OLD bill format code (still working, but without "RechnungDauer2020")

    ************************************************** ****

    Private Function CreateRechnung() As String

    On Error GoTo Err_CreateRechnung

    If Me.Dirty Then
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    End If

    Dim stDocName As String
    Dim daRechDatum As Date
    Dim daSplitDatum As Date
    Dim filename As String

    filename = Environ("temp") + "\Rechnungsbeispiel.pdf"

    daSplitDatum = "01.01.2007"

    If Not IsNull(Me.RDatum.value) And Not IsNull(Me.Art) Then

    daRechDatum = Me.RDatum.value
    If Me.RechnungsZyklus = "Dauerrechnung" Then
    stDocName = "RechnungDauer2016"
    If Me.Art = "M" Then
    Call Monate 'Aktion
    If Me.RZeitraumMonate < 1 Then
    MsgBox "RZeitraum Monate kleiner 1!"
    Exit Function
    End If
    End If
    Else
    Select Case Me.Art
    Case "E"
    If daRechDatum < daSplitDatum Then
    stDocName = "Rechnung2006"
    Else
    stDocName = "Rechnung2007"
    End If
    Case "M"
    If daRechDatum < daSplitDatum Then
    stDocName = "Rechnung2006"
    Else
    stDocName = "Rechnung2007"
    End If

    Call Monate

    If Me.RZeitraumMonate < 1 Then
    MsgBox "RZeitraum Monate kleiner 1!"
    Exit Function
    End If
    End Select

    End If

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    I don't see how either would work. Add missing red END IF to both.

    Code:
    
    ************************************************** *****
    NEW edited code (not working)
    Private Function CreateRechnung() As String
    On Error GoTo Err_CreateRechnung
    
    
    If Me.Dirty Then
    	DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    End If
    
    
    Dim stDocName As String
    Dim daRechDatum As Date
    Dim daSplitDatum As Date
    Dim filename As String
    
    
    filename = Environ("temp") + "\Rechnungsbeispiel.pdf"
    
    
    daSplitDatum = "01.07.2020"
    
    
    If Not IsNull(Me.RDatum.value) And Not IsNull(Me.Art) Then
    	daRechDatum = Me.RDatum.value
    	If Me.RechnungsZyklus = "Dauerrechnung" Then
    		Select Case Me.Art
    			Case "E"
    				If daRechDatum < daSplitDatum Then
    					stDocName = "RechnungDauer2016"
    				Else
    					stDocName = "RechnungDauer2020"
    				End If
    			Case "M"
    				If daRechDatum < daSplitDatum Then
    					stDocName = "RechnungDauer2016"
    				Else
    					stDocName = "RechnungDauer2020"
    				End If
    
    
    				Call Monate 'Aktion
    
    
    				If Me.RZeitraumMonate < 1 Then
    					MsgBox "RZeitraum Monate kleiner 1!"
    					Exit Function
    				End If
    		End Select
    	End If
    End If
    
    
    ************************************************** **********
    
    
    
    
    OLD bill format code (still working, but without "RechnungDauer2020")
    
    
    ************************************************** ****
    
    
    Private Function CreateRechnung() As String
    
    
    On Error GoTo Err_CreateRechnung
    
    
    If Me.Dirty Then
    	DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    End If
    
    
    Dim stDocName As String
    Dim daRechDatum As Date
    Dim daSplitDatum As Date
    Dim filename As String
    
    
    filename = Environ("temp") + "\Rechnungsbeispiel.pdf"
    
    
    daSplitDatum = "01.01.2007"
    
    
    If Not IsNull(Me.RDatum.value) And Not IsNull(Me.Art) Then
    	daRechDatum = Me.RDatum.value
    	If Me.RechnungsZyklus = "Dauerrechnung" Then
    		stDocName = "RechnungDauer2016"
    		If Me.Art = "M" Then
    			Call Monate 'Aktion
    			If Me.RZeitraumMonate < 1 Then
    				MsgBox "RZeitraum Monate kleiner 1!"
    				Exit Function
    			End If
    		End If
    	Else
    		Select Case Me.Art
    			Case "E"
    				If daRechDatum < daSplitDatum Then
    					stDocName = "Rechnung2006"
    				Else
    					stDocName = "Rechnung2007"
    				End If
    			Case "M"
    				If daRechDatum < daSplitDatum Then
    					stDocName = "Rechnung2006"
    				Else
    					stDocName = "Rechnung2007"
    				End If
    
    
    				Call Monate
    
    
    				If Me.RZeitraumMonate < 1 Then
    					MsgBox "RZeitraum Monate kleiner 1!"
    					Exit Function
    				End If
    		End Select
    	End If
    End If

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Further, the date delimiter in Access is #, and in VBA you need to use US format.

    daSplitDatum = #7/1/2020#

    Edit: more on the format: http://allenbrowne.com/ser-36.html#Format
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    AccessNewM is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    4
    Hi Dave, hi pbaldy,

    thanks for your help. I tested both recommendations, unfortunately nothing helped ....
    But I found out, that if I am only using the old code (please see above) and if I am only changing "rechnungdauer2016" to "rechungdauer2020" in the code at this point here:

    If Me.RechnungsZyklus = "Dauerrechnung" Then
    stDocName = "RechnungDauer2016"

    ...
    nothing is happening, although the report "RechnungDauer2020" exists.
    So the problem could be the "RechnungDauer2020"-report.
    How did I create this report? --> I copied the "RechnungDauer2016" report only and made the necessary adjustments.
    Do I have to connect this "report" anywhere so that it is working in the code before?

    Thank for your quick help and best regards - stay healthy

    Your AccessNewM

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You don't actually do anything with stDocName in this procedure. Perhaps your problem is in Monate, which is presumably a function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    AccessNewM is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    4
    Hi Paul,

    thanks for this realtime answer.
    I guess "monate" is not the problem, since we use this information for printing on the bill...
    My question is..., why does "RechnungDauer2016" in the old code work... and "RechnungDauer2020" in the old code note?
    It seems like that there is no connection to this new "report" "RechnunDauer2020", doesnīt it?

    BR

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I'm saying that this line:

    stDocName = "RechnungDauer2016"

    sets a variable named stDocName but that variable isn't actually used for anything, unless I'm blind. Can you attach the db here with instructions on how to recreate the problem? I'm guessing that the 2016 report is actually called from someplace else.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    AccessNewM is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    4
    Hi Paul,

    I guess this variable is needed for creating a doc.-/ a pdf.-file out of this report (this is what acutually happens at a later step...).
    But at this moment this functionality is not important since we need only the right report shown ("RechnungDauer2020"). But it still shows the "RechnungDauer2016"...

    BR

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I guess I'm stumped. The variable may be needed, but it is not used in the code you posted, so I'm not surprised that changing its value here isn't accomplishing your goal. If there's more code, perhaps you can post that if not the whole db.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 31
    Last Post: 08-15-2019, 12:33 PM
  2. Need help correcting Code
    By lccrews in forum Access
    Replies: 3
    Last Post: 02-02-2018, 07:04 PM
  3. creation alpha numeric code
    By Jen0dorf in forum Access
    Replies: 1
    Last Post: 05-09-2016, 11:52 AM
  4. Replies: 4
    Last Post: 04-05-2016, 07:33 AM
  5. Asistance correcting an error in my Code
    By VWSpeedyB in forum Modules
    Replies: 2
    Last Post: 06-30-2015, 08:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums