Help!

PC-Problemen?
De vrijwilligers van Oplossing.be zoeken gratis met u mee!

Hulp bij posten

Recente topics

Auteur Topic: Saven met optie veld  (gelezen 64425 keer)

0 leden en 2 gasten bekijken dit topic.

Offline adri

  • Ervaren lid
  • ***
  • Berichten: 421
  • Geslacht: Man
  • De Oplossing!
Saven met optie veld
« Gepost op: 14 juni 2019, 11:11:50 »
Met onderstaande code save ik een rapport met datum en als naam Overzicht.
Op mijn formulier heb ik evenwel 2 keuze mogelijkheden om mijn rapport te beperken: velden per Jaar en per Transactie (aankoop, verkoop...)
Nu zou ik graag saven met de evt gekozen mogelijkheid.
Als ik niks kies dan is naam: Datum en Overzicht.
Als ik jaar kies dan is naam: Datum en overzicht en waarde van veld Jaar.
Als ik Transactie kies dan is naam: Datum en overzicht en waarde van veld Transactie.
Als ik Transactie en Jaar kies dan : Datum en overzicht en waarden van velden Transactie en Jaar.

 Private Sub CmdSave_Click()
If Me.FilePath = "" Or IsNull(Me.FilePath) Then
    MsgBox "Kies een path!"
    Exit Sub
End If
If Right(Me.FilePath, 1) <> "\" Then Me.FilePath = Me.FilePath & "\"
If Dir(FilePath, vbDirectory) = "" Then
    Shell ("cmd /c mkdir """ & FilePath & """")
End If
    pathName = Me.FilePath
    fileName = pathName & " " & Format(Date, "yyyy-mm-dd") & " " & "Overzicht.pdf"
    'fileName = pathName & " " & Format(Date, "yyyy-mm-dd") & " " & "Overzicht.pdf" & "Jaar"
     'fileName = pathName & " " & Format(Date, "yyyy-mm-dd") & " " & "Overzicht.pdf" & "Transactie"
      'fileName = pathName & " " & Format(Date, "yyyy-mm-dd") & " " & "Overzicht.pdf" & "Jaar" & "Transactie"

    DoCmd.OutputTo acOutputReport, "rptOverzicht", acFormatPDF, fileName, , , , acExportQualityPrint
    DoCmd.Close acReport, "rptOverzicht"
End Sub

Bedoeling is dus dat als ik op de save knop druk dat er dan, als er niks aangeduid is in de velden transactie en jaar, de 1é mogelijkheid van pas komt.
Als er wel iets in 1 vd velden of in allebei: de andere mogelijkheden. 

Het is waarschijnlijk met if then, maar geraak er niet uit.
De vet, cursieve code toont wat ik wil.
Asus k750jb.
Windows 10 Home   NLD 64bit
Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz 2401
X750JB
NVIDIA GeForce GT 740M        2048MB 1600 x 900
Realtek High Definition Audio
Nr: 1 Model: PLEXTOR PX-256M5S
C:\ NTFS 183,18GB 6,54GB 12 173MB
AV: AVG
FW: Windows Firewal Enabled: True

Offline dizzl

  • Ambassadeur
  • *****
  • Berichten: 2.345
  • I've Upped my standards,now,up yours!
Re: Saven met optie veld
« Reactie #1 Gepost op: 14 juni 2019, 19:09:00 »
"jaar" en "transactie" zijn wat voor soort velden? Checkbox of radiobuttons?
Systeem  : Intel Core i5-4440 3.1Ghz, 3.1GHz 16Giga Ram 64Bits
Software : Windows 10 professional, Avira, Office 2016 Professional

Offline adri

  • Ervaren lid
  • ***
  • Berichten: 421
  • Geslacht: Man
  • De Oplossing!
Re: Saven met optie veld
« Reactie #2 Gepost op: 15 juni 2019, 07:17:24 »
Beiden zijn keuzelijsten.
Jaar bevat alle jaartallen waarin er transacties geweest zijn.
Transacties is een keuzelijst gebonden aan een id nummer.
Aankoop is 1, verkoop is 2....
Asus k750jb.
Windows 10 Home   NLD 64bit
Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz 2401
X750JB
NVIDIA GeForce GT 740M        2048MB 1600 x 900
Realtek High Definition Audio
Nr: 1 Model: PLEXTOR PX-256M5S
C:\ NTFS 183,18GB 6,54GB 12 173MB
AV: AVG
FW: Windows Firewal Enabled: True

Offline dizzl

  • Ambassadeur
  • *****
  • Berichten: 2.345
  • I've Upped my standards,now,up yours!
Re: Saven met optie veld
« Reactie #3 Gepost op: 15 juni 2019, 10:31:22 »
Ik zie het niet. Kan je een schermafdruk?
Systeem  : Intel Core i5-4440 3.1Ghz, 3.1GHz 16Giga Ram 64Bits
Software : Windows 10 professional, Avira, Office 2016 Professional

Offline adri

  • Ervaren lid
  • ***
  • Berichten: 421
  • Geslacht: Man
  • De Oplossing!
Re: Saven met optie veld
« Reactie #4 Gepost op: 15 juni 2019, 12:24:44 »
hierbij een schermafdruk
Asus k750jb.
Windows 10 Home   NLD 64bit
Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz 2401
X750JB
NVIDIA GeForce GT 740M        2048MB 1600 x 900
Realtek High Definition Audio
Nr: 1 Model: PLEXTOR PX-256M5S
C:\ NTFS 183,18GB 6,54GB 12 173MB
AV: AVG
FW: Windows Firewal Enabled: True

Offline dizzl

  • Ambassadeur
  • *****
  • Berichten: 2.345
  • I've Upped my standards,now,up yours!
Re: Saven met optie veld
« Reactie #5 Gepost op: 17 juni 2019, 18:18:53 »
Ik zie de keuzelijsten met Aankoop, Transactie of beiden niet maar je code zou op deze moeten lijken.
Private Sub CmdSave_Click()
If Me.FilePath = "" Or IsNull(Me.FilePath) Then
    MsgBox "Kies een path!"
    Exit Sub
End If
If Right(Me.FilePath, 1) <> "\" Then Me.FilePath = Me.FilePath & "\"
If Dir(FilePath, vbDirectory) = "" Then
    Shell ("cmd /c mkdir """ & FilePath & """")
End If
    pathName = Me.FilePath

Select Case Transactie.value
    Case Is "Jaar"
        fileName = pathName & " " & Format(Date, "yyyy-mm-dd") & " " & "Overzicht.pdf" & "Jaar"
    Case Is "Transactie
        fileName = pathName & " " & Format(Date, "yyyy-mm-dd") & " " & "Overzicht.pdf" & "Transactie"   
    Case Else
        fileName = pathName & " " & Format(Date, "yyyy-mm-dd") & " " & "Overzicht.pdf" & "Jaar" & "Transactie"
End Select


    DoCmd.OutputTo acOutputReport, "rptOverzicht", acFormatPDF, fileName, , , , acExportQualityPrint
    DoCmd.Close acReport, "rptOverzicht"
End Sub
Systeem  : Intel Core i5-4440 3.1Ghz, 3.1GHz 16Giga Ram 64Bits
Software : Windows 10 professional, Avira, Office 2016 Professional

Offline adri

  • Ervaren lid
  • ***
  • Berichten: 421
  • Geslacht: Man
  • De Oplossing!
Re: Saven met optie veld
« Reactie #6 Gepost op: 18 juni 2019, 08:42:50 »
heb het zo kunnen oplossen:

 Dim fileName As String

    With Me

        If .FilePath & "" = "" Then
            MsgBox "Kies een path!"

        Else

            If Right(.FilePath, 1) <> "\" Then .FilePath = .FilePath & "\"

            If Dir(.FilePath, vbDirectory) = "" Then MkDir .FilePath

            fileName = .FilePath & Format(Date, "yyyy-mm-dd") & " Overzicht" _
                 & Nz(" " + .KeuzeDatum & " " + .KeuzeTransActie.Column(1), "Totaal") & ".pdf"

            DoCmd.OutputTo acOutputReport, "rptOverzicht", acFormatPDF, fileName, , , , acExportQualityPrint

        End If

    End With
Asus k750jb.
Windows 10 Home   NLD 64bit
Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz 2401
X750JB
NVIDIA GeForce GT 740M        2048MB 1600 x 900
Realtek High Definition Audio
Nr: 1 Model: PLEXTOR PX-256M5S
C:\ NTFS 183,18GB 6,54GB 12 173MB
AV: AVG
FW: Windows Firewal Enabled: True

Offline adri

  • Ervaren lid
  • ***
  • Berichten: 421
  • Geslacht: Man
  • De Oplossing!
Re: Saven met optie veld
« Reactie #7 Gepost op: 18 juni 2019, 09:08:38 »
nu zou ik nog graag een msgbox krijgen als het bestand dat ik save al bestaat.
waar moet ik dat juist zetten en welke code.
overschrijven of niet....
Asus k750jb.
Windows 10 Home   NLD 64bit
Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz 2401
X750JB
NVIDIA GeForce GT 740M        2048MB 1600 x 900
Realtek High Definition Audio
Nr: 1 Model: PLEXTOR PX-256M5S
C:\ NTFS 183,18GB 6,54GB 12 173MB
AV: AVG
FW: Windows Firewal Enabled: True

Offline SoftAid

  • Administrator
  • Ambassadeur
  • *****
  • Berichten: 20.128
  • Geslacht: Man
  • Nobody is perfect, not even me...
Re: Saven met optie veld
« Reactie #8 Gepost op: 18 juni 2019, 10:25:02 »
Probeer eens op deze manier (niet getest):

Dim fileName As String

    With Me

        If .FilePath & "" = "" Then
            MsgBox "Kies een path!"

        Else

            If Right(.FilePath, 1) <> "\" Then .FilePath = .FilePath & "\"

            If Dir(.FilePath, vbDirectory) = "" Then MkDir .FilePath
            If Excist .FilePath & Format(Date, "yyyy-mm-dd") & " Overzicht" _
                 & Nz(" " + .KeuzeDatum & " " + .KeuzeTransActie.Column(1), "Totaal") & ".pdf"
            Msgbox ("dit bestand bestaat reeds")
            Exit sub
            Else
            fileName = .FilePath & Format(Date, "yyyy-mm-dd") & " Overzicht" _
                 & Nz(" " + .KeuzeDatum & " " + .KeuzeTransActie.Column(1), "Totaal") & ".pdf"

            DoCmd.OutputTo acOutputReport, "rptOverzicht", acFormatPDF, fileName, , , , acExportQualityPrint

        End If
        End If
    End With

:) SoftAid :)             
Maximum grootte bijlagen vergroot naar 4 MB
Dubbelposten, het posten op verschillende forums van dezelfde vraag, dient op
voorhand gemeld te worden, met een link naar het topic op de andere site.
Overtreding van deze regel kan bestraft worden met verbanning !

Offline adri

  • Ervaren lid
  • ***
  • Berichten: 421
  • Geslacht: Man
  • De Oplossing!
Re: Saven met optie veld
« Reactie #9 Gepost op: 18 juni 2019, 11:38:37 »
krijg fout bij else onder exit sub.
Asus k750jb.
Windows 10 Home   NLD 64bit
Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz 2401
X750JB
NVIDIA GeForce GT 740M        2048MB 1600 x 900
Realtek High Definition Audio
Nr: 1 Model: PLEXTOR PX-256M5S
C:\ NTFS 183,18GB 6,54GB 12 173MB
AV: AVG
FW: Windows Firewal Enabled: True

Offline dizzl

  • Ambassadeur
  • *****
  • Berichten: 2.345
  • I've Upped my standards,now,up yours!
Re: Saven met optie veld
« Reactie #10 Gepost op: 18 juni 2019, 19:53:51 »
Voor mij is dit te chaotisch. Kan ik je het origineel bestand hier zetten?
Systeem  : Intel Core i5-4440 3.1Ghz, 3.1GHz 16Giga Ram 64Bits
Software : Windows 10 professional, Avira, Office 2016 Professional

Offline adri

  • Ervaren lid
  • ***
  • Berichten: 421
  • Geslacht: Man
  • De Oplossing!
Re: Saven met optie veld
« Reactie #11 Gepost op: 19 juni 2019, 08:13:10 »
Dat kan ik moeilijk doen dizzl.
Bevat te veel persoonlijke info.
Asus k750jb.
Windows 10 Home   NLD 64bit
Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz 2401
X750JB
NVIDIA GeForce GT 740M        2048MB 1600 x 900
Realtek High Definition Audio
Nr: 1 Model: PLEXTOR PX-256M5S
C:\ NTFS 183,18GB 6,54GB 12 173MB
AV: AVG
FW: Windows Firewal Enabled: True

Offline adri

  • Ervaren lid
  • ***
  • Berichten: 421
  • Geslacht: Man
  • De Oplossing!
Re: Saven met optie veld
« Reactie #12 Gepost op: 20 juni 2019, 10:44:24 »
Dit is de oplossing:
Dim fileName As String, booSave As Boolean

    With Me

        If .FilePath & "" = "" Then
            MsgBox "Kies een path!"

        Else

            If Right(.FilePath, 1) <> "\" Then .FilePath = .FilePath & "\"

            If Dir(.FilePath, vbDirectory) = "" Then MkDir .FilePath

            fileName = .FilePath & Format(Date, "yyyy-mm-dd") & " Overzicht" _
                 & Nz(" " + .KeuzeDatum & " " + .KeuzeTransActie.Column(1), "Totaal") & ".pdf"

            booSave = True
            If Dir(fileName) <> "" Then
                If MsgBox("File already exists, do you want to overwrite?", vbYesNo) = vbNo Then booSave = False
            End If
            If booSave Then DoCmd.OutputTo acOutputReport, "rptOverzicht", acFormatPDF, fileName, , , , acExportQualityPrint

        End If

    End With
Asus k750jb.
Windows 10 Home   NLD 64bit
Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz 2401
X750JB
NVIDIA GeForce GT 740M        2048MB 1600 x 900
Realtek High Definition Audio
Nr: 1 Model: PLEXTOR PX-256M5S
C:\ NTFS 183,18GB 6,54GB 12 173MB
AV: AVG
FW: Windows Firewal Enabled: True

 


www.combell.com