Report (1 Viewer)

m-taha

New member
Local time
Today, 00:28
Joined
Dec 6, 2019
Messages
17
hi i'm Mathani
i'm not very well aversed with VBA i only started two moth ago, so i need help!
i have a code(in a standard module) where i would like it to generalize the name of the picture in a report (image control name) and the name of the report that i'm refering to , because i want to use it on other reports with image controls as well, instead chnging the names everytime i use it on a different report .

this is my code :

note : (pfad = path) , (bericht = report) , (bild = picture/image)

Dim pfad As String
Dim Bild As Access.image
Dim Bericht As Access.Report

Set Bild127 = Bild
Set Bericht1 = Bericht

pfad = "C:\Entwicklung\Mathani\QR_PIC\" & filename & ".png"
Reports!Bericht1.Bild127.Picture = pfad

i know my code is Wrong hhhhh, well that's why i'm here, so when i run this it gives me the error message ( Runtime Error 2451 : The Bericht1 that you entered is either misspelled or refers to a report that is not open or does not exist). And for the picture sometimes i get a message 424 that object necessary.

Thank you so much in advance ❤☺😇
i am open to any suggestions that would make the code better/more efficient/easier anything literally anything
 

vba_php

Forum Troll
Local time
, 18:28
Joined
Oct 6, 2019
Messages
2,553
reports aren't my greatest strength, Mathani, but here are a few notes for you:
Code:
note : (pfad = path) , (bericht = report) , (bild = picture/image)

  Dim pfad As String
  Dim Bild As Access.image
  Dim Bericht As Access.Report
   
        Set Bild127 = Bild
        Set Bericht1 = Bericht

             pfad = "C:\Entwicklung\Mathani\QR_PIC\" & filename & ".png"
             Reports!Bericht1.Bild127.Picture = pfad
I've never used Access.image or Access.report but i'm guessing there's nothing wrong it because they are part of access's object model. so, this:
so when i run this it gives me the error message ( Runtime Error 2451 : The Bericht1 that you entered is either misspelled or refers to a report that is not open or does not exist).
is probably a simple mis-step I would guess. Kind of like m current question in the excel forum! :) maybe this previous thread will help: https://www.access-programmers.co.uk/forums/threads/i-am-getting-run-time-error-2451.214442/ .
And for the picture sometimes i get a message 424 that object necessary.
you get that error *sometimes*? that kind of sounds like sometimes you've got the report open when you run the code and sometimes you don't. hopefully this helps a little bit...
 

m-taha

New member
Local time
Today, 00:28
Joined
Dec 6, 2019
Messages
17
reports aren't my greatest strength, Mathani, but here are a few notes for you:I've never used Access.image or Access.report but i'm guessing there's nothing wrong it because they are part of access's object model. so, this:is probably a simple mis-step I would guess. Kind of like m current question in the excel forum! :) maybe this previous thread will help: https://www.access-programmers.co.uk/forums/threads/i-am-getting-run-time-error-2451.214442/ .you get that error *sometimes*? that kind of sounds like sometimes you've got the report open when you run the code and sometimes you don't. hopefully this helps a little bit...
thank you for replying 😄
i found out that the *sometimes* is because of this 1580993992360.png i tried to change the code to see if it would work 😅😅 but it didn't

there's this when i dim Bericht1 and Bild127 accordingly and type Reports!Bericht1.Bild127.Picture = pfad it works even without commenting out the Set part (though it doesn't seem like it's the issue), but if i dim Bericht and Bild and type Reports!Bericht.Bild.Picture = pfad it doesn't :(
all i want is just to find a way to be able to use the code function on any report without having to type the names of the reports and image controls everytime
 

vba_php

Forum Troll
Local time
, 18:28
Joined
Oct 6, 2019
Messages
2,553
all i want is just to find a way to be able to use the code function on any report without having to type the names of the reports and image controls everytime
well there's a number of ways you can get that done. I work a lot more with forms rather than reports, but I'm terrible at designing anything, especially reports. I write source code from scratch and automate things when requested. but I believe, you could do something like this behind a button on a form (or something similar):
Code:
'note : (pfad = path) , (bericht = report) , (bild = picture/image)

public function openRpt (pfad as string, Bericht as access.report)
   set reports![Report Name]!Bild = Bild
   set reports![Report Name]Bericht1 = Bericht

             Reports!Bericht1.Bild127.Picture = pfad
and then you would write this behind a button on a form or something like that (on the "onclick" event:
Code:
=openRpt("C:\Entwicklung\Mathani\QR_PIC\" & filename & ".png", "name of report")
that code probably won't work, but I wrote it to show you how to translate what you did into what *does* work in Access. more than likely you can't include image objects and report objects inside a function call behind a button like that. and if that is true, all you have to do is tranform them to strings that refer to the names of the objects themselves, like:
Code:
=openRpt("path of image", "name of report")
then a function like:
Code:
public function openRpt (pfad as string, Bericht as string)

   docmd.openreport Bericht, acviewpreview
   reports(Bericht).controls("imageControl") = pfad
and access is absolutely terrible at accepting *some* syntax and not accepting *some other* syntax. That problem comes with every version, you may have to change that code to make it work. this forum has many articles on control and object referencing, which are the key words you should search on, I would guess. :)
 

m-taha

New member
Local time
Today, 00:28
Joined
Dec 6, 2019
Messages
17
i didn't know how to apply your advice on my code so i just put the entire code here

Code:
Public Function qr_erstellen(k_name As String, d_name As String, k_plz As String, d_plz As String, k_stadt As String, d_stadt As String, k_land As String, d_land As String, k_str As String, d_str As String, k_str_nr As String, d_str_nr As String, k_betrag As Single, d_iban As String) As PngByteQRCode


Dim qr As QRCoderVBA
Set qr = New QRCoderVBA

Dim k_referenz As String
Dim filename As String
Dim man As String
Dim woman As String

man = Herr
woman = Frau
k_name = "greenwood"
k_plz = "1254"
k_stadt = "Stadt"
k_land = "CH"
k_str = "564"
k_str_nr = "645"
k_betrag = 56484
d_name = "Damian"
d_plz = "1254"
d_stadt = "Stadt"
d_land = "CH"
d_str = "5"
d_str_nr = "56484"
d_iban = "CH4431999123000889012"


filename = "QR_" & k_name & Date


qr.setCreditor k_name, k_plz, k_stadt, k_land, k_str, k_str_nr
qr.setAmount k_betrag
qr.setDebitor d_name, d_plz, d_stadt, d_land, d_str, d_str_nr
qr.setIban d_iban
qr.setReference ("")
qr.GenerateSwissQRCode ("C:\Entwicklung\Mathani\QR_PIC\" & filename & ".png")



     ' Die QR bild ordnerpfad in tabellenfeld speichern
     ' tablle path ist eine beispiel tabelle

     Dim pfad As String
     Dim Bild As image
     Dim Bericht As Access.Report

            Set Bild127 = Bild
            Set Bericht1 = Bericht

             pfad = "C:\Entwicklung\Mathani\QR_PIC\" & filename & ".png"
             Reports!Bericht1.Bild127.Picture = pfad

         'png löschen
               Kill pfad


End Function


so it generates a QR code from the given fields, i orignally made it in excel as excel form and it worked pretty well, but i needed in access as well to add to the bills we generate from both excel and access
so i already have a button that calls the function and specifies the informations in the parameters and generates the QR code (the middle section was before i added the values to the button 😅 😅 but it's not an issue)

the issue is if i want to use it with different reports from different sources it needs to be more general 😓 but i couldn't get it to do that



Code:
Private Sub Befehl388_Click()
    Call mdlQR.qr_erstellen("Müller", "Meier", "1245", "7854", "paris", "berlin", "CH", "SE", "kstrasse", "dstrasse", "kstrnr", "dstrnr", "45698", "CH4431999123000889012")
End Sub
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom