Avatar billede martens Guru
16. april 2019 - 22:26 Der er 1 kommentar og
1 løsning

Problem med CONST & FELTNAVN i path

Hej I skape hjerner !
Jeg har et problem med nedenståede kode, hvor jeg forsøger at indsætte et billede som signatur ...
Det er en database, der benyttes af flere brugere, så jeg tænkte at istedet for den sædvanlige textsignatur kunne der benyttes et billede.
så brugernes signatur eksempelvis hedder %logonname% & ".jpg" ( databasen benyttes på Windows domæne, så intet problem med at hente brugernes logon-navne. )

problemet er omkring  linen med :  ' Const MyPiX = "C:\#_Export\PIX\" & Me.imagename & "\"
her vil jeg gerne have værdien fra formularen jeg står på med data fra tekstboken med navnet 'imagename"

Håber det giver mening !
mvh martens
---------------------------------------------------------------------------------

Kode :

Private Sub cmb_send_with_attachments_CLEAN_CODE_Click()
FileCopy "C:\#_Export\XML_1\tbl cars_locations_etc.xml", "C:\#_Export\XML_4\tbl cars_locations_etc.xml"
FileCopy "C:\#_Export\XML_2\tbl_Cars_Pools_POC_info.XML", "C:\#_Export\XML_4\tbl_Cars_Pools_POC_info.XML"
FileCopy "C:\#_Export\XML_3\current_bookings.txt", "C:\#_Export\XML_4\current_bookings.txt"
FileCopy "C:\#_Import\#_Fixed_Files_4_Access\carpools.xlsx", "C:\#_Export\XML_4\carpools.xlsx"


    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Dim strPath As String
    Dim strFilter As String
    Dim strFile As String
    Dim imagename As String

    ''
    'Hvorfor kan jeg IKKE dette ?
  ' Const MyPiX = "C:\#_Export\PIX\" & Me.imagename & "\"
    Const MyPiX = "C:\#_Export\PIX\database.jpg"
 
    ''
    strPath = "C:\#_Export\XML_4\"
    strFilter = "*.*"
    strFile = Dir(strPath & strFilter)

    If strFile <> "" Then

        Set appOutLook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutLook.CreateItem(olMailItem)

        With MailOutLook
        .Attachments.Add MyPiX
      '.Attachments.Add MyPiX2
            .BodyFormat = olFormatRichText
            .To = "modtager@domain.dk"
            .CC = "modtager@gmail.com"
            .BCC = "modtager@mail.dk"
            .Subject = "data fra den store mester ;o) " & Date & " " & Time
       
                ' her henter jeg værdien 'me.imagename' fra formularen - virker fint !
            .HTMLBody = "<br><B>MDS - martens data service </B><br>" & "<img src='cid:" & Me.imagename & "'" & "width='200' height='200'><br>" & Me.Text4
               
         
         

Do While Len(strFile) > 0
            .Attachments.Add (strPath & strFile)
       
                strFile = Dir
        Loop
   
            '.Send      'Sender mail UDEN visning INDEN afsendelse
            .Display    'Viser mail INDEN afsendelse
        End With
    Else
        MsgBox "No file matching " & strPath & strFilter & " found." & vbCrLf & _
                "Processing terminated."
        Exit Sub
    End If
End Sub
Avatar billede terry Ekspert
17. april 2019 - 10:42 #1
If you remove the ' so the line in question is no longer a comment then compile the code, you'll get an error.

"Constant expression required"
The next line doesn't give an error.

This is because the first line your trying to give MyPIX a variable value, IE one which can change. Bit CONST values can not be changed.

CONSTANT: (Always the same)
A named item that retains a constant value throughout the execution of a program. A constant can be a string or numeric literal, another constant, or any combination that includes arithmetic or logical operators except Is and exponentiation. Each host application can define its own set of constants. Additional constants can be defined by the user with the Const statement. You can use constants anywhere in your code in place of actual values.
Avatar billede terry Ekspert
17. april 2019 - 10:42 #2
Why cant you just use a string?
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester