Solved form id number to directory (1 Viewer)

rainbows

Registered User.
Local time
Today, 08:43
Joined
Apr 21, 2017
Messages
425
1636226396073.png

hi I would like to be able to save this form in PDF Format with a file name from the ARNO ie file no 7 . I would like it to goto my documents into a folder that's name comes from the field " company" as this is variable, thanks steve
 

mike60smart

Registered User.
Local time
Today, 15:43
Joined
Aug 6, 2017
Messages
1,899
Why would you want to save it as a PDF? You can access the data at any time from within Access.
 

rainbows

Registered User.
Local time
Today, 08:43
Joined
Apr 21, 2017
Messages
425
To be honest my Boss asked for it although I was in the same mind as you
 

mike60smart

Registered User.
Local time
Today, 15:43
Joined
Aug 6, 2017
Messages
1,899
Ok If you have to do it then it would be best to create a query for the fields you require.
Then create a Report based on the query.
Then on the Form you would have a Command Button with a Filter for the specific "ARNO" to Save the Report as a PDF
 

rainbows

Registered User.
Local time
Today, 08:43
Joined
Apr 21, 2017
Messages
425
Code:
Private Sub Command436_Click()
Dim FILENAME As String
Dim FALEPATH As String
Dim COMPANY1 As String
Dim company2 As String


If company = 1 Then

FILENAME = "ARNO" & "  " & Me.ARNO
filepath = "C:\Users\steve\Documents\ppi" & FILENAME & ".pdf"
DoCmd.OutputTo acOutputQuery, "Individual ARNO", acFormatPDF, filepath

If company = 2 Then

FILENAME = "ARNO" & "  " & Me.ARNO
filepath = "C:\Users\steve\Documents\API" & FILENAME & ".pdf"
DoCmd.OutputTo acOutputQuery, "Individual ARNO", acFormatPDF, filepath

 End If
MsgBox " file has been saved "
', vbInformation, "save confirmed"


End If
End Sub








i have tried to use the query method that was suggested but i have run into 2 problems
1 it dont take me to the folder ppi it just takes me to the folder documents and calls the pdf name ppi arno 10 if it is the `10th record
2 it only gives me a record when the company is 1 ie " ppi " not when it is api
thank you for your help
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:43
Joined
May 7, 2009
Messages
19,175
Code:
Private Sub Command436_Click()
Dim FILENAME As String
Dim FALEPATH As String
Dim COMPANY1 As String
Dim company2 As String


If company = 1 Then

FILENAME = "ARNO" & "  " & Me.ARNO
filepath = "C:\Users\steve\Documents\ppi\" & FILENAME & ".pdf"
DoCmd.OutputTo acOutputQuery, "Individual ARNO", acFormatPDF, filepath

If company = 2 Then

FILENAME = "ARNO" & "  " & Me.ARNO
filepath = "C:\Users\steve\Documents\API\" & FILENAME & ".pdf"
DoCmd.OutputTo acOutputQuery, "Individual ARNO", acFormatPDF, filepath

 End If
MsgBox " file has been saved "
', vbInformation, "save confirmed"


End If
Application.FollowHyperlink Replace$(filepath, Dir$(filepath), "")
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:43
Joined
Sep 21, 2011
Messages
14,056
You might want to start indenting your code, as I cannot see that working correctly?
 

rainbows

Registered User.
Local time
Today, 08:43
Joined
Apr 21, 2017
Messages
425
Code:
Private Sub Command437_Click()
Dim FILENAME As String
Dim filepath As String
 Dim varFolder As Variant

 FILENAME = "ARNO" & "  " & Me.ARNO
 
        If Forms![Issue LIST]![company] = "1" Then
 DoCmd.OutputTo acOutputReport, "individual arno1", acFormatPDF, "c:\users\steve\documents\all action request reports\ppi action request\" & FILENAME & " .pdf"
     End If
    
          
      If Forms![Issue LIST]![company] = "2" Then
  DoCmd.OutputTo acOutputReport, "individual arno1", acFormatPDF, "c:\users\steve\documents\all action request reports\api action requests\" & FILENAME & " .pdf"
     End If
    
    If Forms![Issue LIST]![company] = "3" Then
  DoCmd.OutputTo acOutputReport, "individual arno1", acFormatPDF, "c:\users\steve\documents\all action request reports\apic action requests\" & FILENAME & " .pdf"
 
  End If
 
If Forms![Issue LIST]![company] = "4" Then
                DoCmd.OutputTo acOutputReport, "individual arno1", acFormatPDF, "c:\users\steve\documents\all action request reports\temp action requests\" & FILENAME & " .pdf"
End If

End Sub




I want to thank you all for helping me with this code . it is working good now . but I realise maybe this is not the correct way as if I want to add others I have to come back into this code to do it

I have a table called company which has 4 fields , id , company, director , and filepath that I have just added id 1 has Company ppi -engineering in it. with a file path of . is t possible that the code could just get the file path from here?

thanks steve
Company

filepath
"c:\users\steve\documents\all action request reports\ppi action requests\" & FILENAME & " .pdf"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:43
Joined
May 7, 2009
Messages
19,175
just Dlookup the filepath?

DoCmd.OutputTo acOutputReport, "individual arno1", acFormatPDF, Dlookup("filepath", "companyTable", "ID = " & Val(Me![company])) & FILENAME & ".pdf"


or you can add the filepath to your company combobox and use it's Column number:

DoCmd.OutputTo acOutputReport, "individual arno1", acFormatPDF, Me![company].Column(2) & FILENAME & ".pdf"
 

rainbows

Registered User.
Local time
Today, 08:43
Joined
Apr 21, 2017
Messages
425
1636360120398.png

when I first run it it said "companytable"was not valid, so I removed the word table then run t again and you can see it did not go to the proper folder it created a file just call ppi action requests. my filepath also included filename and pdf in it as you can see I am a novice at this but keep trying thank you
 

rainbows

Registered User.
Local time
Today, 08:43
Joined
Apr 21, 2017
Messages
425
Code:
Private Sub Command438_Click()

Dim FILENAME As String
Dim strFullPath As Variant
    Dim folderpath As Variant
    Dim foldername As String

 FILENAME = "ARNO" & "  " & Me.ARNO
      
    Dim varfolder As String
    
   If company = 1 Then company = "PPI-Engineering"
    
    End If
   If company = 2 Then company = "API-Engineering"
    End If
   If company = 3 Then company = "API-Capacitors"
    End If
   If company = 3 Then company = "temp"
  
     End If
    
  
    
             varfolder = DLookup("filepath", "company")
      
            
         varfolder1 = varfolder & "\" & company & "\" & FILENAME & ".pdf"
        
          
            Me.Dirty = False
            
            
            DoCmd.OutputTo acOutputReport, "INDIVIDUAL ARNO", acFormatPDF, varfolder1
          
          

   End Sub




hi, this is nearly working as individually they work fine but with all the endif it fails due to block if , I have tried else if etc without success can you pleas advise what is wrong
thank you steve
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:43
Joined
Sep 21, 2011
Messages
14,056
If you are going to write If statements like that, then no Endif needed?
They are for
If....
do domething
EndIf

Plus you are overwriting company 3 with Temp?

Indent your code properly. It makes it easier to see errors (well it does for me :( )

As I mentioned before, perhaps look at the Select Case statement?, easier to understand?
 

rainbows

Registered User.
Local time
Today, 08:43
Joined
Apr 21, 2017
Messages
425
To everyone , I want to thank you all for your help , as it now working as I needed Next part of project to do now
 

Users who are viewing this thread

Top Bottom