pull 5 charectors from a varible (1 Viewer)

rainbows

Registered User.
Local time
Today, 11:15
Joined
Apr 21, 2017
Messages
425
Code:
If company = 1 Then company1 = "PPI-Engineering"
  
   If company = 2 Then company1 = "API-Engineering"


I am trying to pull the first 5 charectors OF the varible "company 1 "   either PPI-E   , OR API-E.  bur with no lucj   can you please assist with this  thanks steve
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:15
Joined
Oct 29, 2018
Messages
21,473
Try
Code:
Left(company1, 5)
 

rainbows

Registered User.
Local time
Today, 11:15
Joined
Apr 21, 2017
Messages
425
I did try that and it just gives me "compa"
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:15
Joined
Feb 19, 2002
Messages
43,274
It is always helpful when you post the code YOU used. theDBguy gave you pseudo code. Looks like you used his names and since company1 isn't the name of your variable, Access helpfully converted it to a string and so you are seeing the first 5 characters of "company1", NOT the first 5 of some control or variable.
 

rainbows

Registered User.
Local time
Today, 11:15
Joined
Apr 21, 2017
Messages
425
Code:
Private Sub Command437_Click()
Dim FILENAME As String
Dim strFullPath As Variant
    Dim folderpath As Variant
    Dim foldername As String
      Dim varfolder2 As String
      Dim company1 As String

 FILENAME = Left("COMPANY1", 5) & "   " & "ARNO" & "  " & Me.ARNO
      
    Dim varfolder As String
    
   If company = 1 Then company1 = "PPI-Engineering"
  
   If company = 2 Then company1 = "API-Engineering"

   If company = 3 Then company1 = "API-Capacitors"
 
   If company = 4 Then company1 = "temp"
  
             '   FILENAME = "ARNO" & "  " & Me.ARNO
  
               varfolder = DLookup("filepath", "company")
                  
               varfolder1 = varfolder & "\" & company1 & "\" & FILENAME & ".pdf"
                  
               Me.Dirty = False

DoCmd.OutputTo acOutputReport, "INDIVIDUAL ARNO", acFormatPDF, varfolder1
          
End Sub


this is the code I have used ,

thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:15
Joined
Oct 29, 2018
Messages
21,473
Code:
Private Sub Command437_Click()
Dim FILENAME As String
Dim strFullPath As Variant
    Dim folderpath As Variant
    Dim foldername As String
      Dim varfolder2 As String
      Dim company1 As String

FILENAME = Left("COMPANY1", 5) & "   " & "ARNO" & "  " & Me.ARNO
    
    Dim varfolder As String
  
   If company = 1 Then company1 = "PPI-Engineering"

   If company = 2 Then company1 = "API-Engineering"

   If company = 3 Then company1 = "API-Capacitors"

   If company = 4 Then company1 = "temp"

             '   FILENAME = "ARNO" & "  " & Me.ARNO

               varfolder = DLookup("filepath", "company")
                
               varfolder1 = varfolder & "\" & company1 & "\" & FILENAME & ".pdf"
                
               Me.Dirty = False

DoCmd.OutputTo acOutputReport, "INDIVIDUAL ARNO", acFormatPDF, varfolder1
        
End Sub


this is the code I have used ,

thanks
Try taking out the double quotes around your variable. I didn't use any in my example.

PS. Also, you need to use the Left() function after you have assigned a value to your variable. So, try moving it down a few lines, after the If statements.
 

plog

Banishment Pending
Local time
Today, 13:15
Joined
May 11, 2011
Messages
11,646
Code:
 FILENAME = Left("COMPANY1", 5) & "   " & "ARNO" & "  " & Me.ARNO

1. You are not using a variable when you put quote marks around something you are using a literal--as in literally what appears between the quote marks which in that case is the 8 characters "COMPANY1".

2. Even if you remove the quote marks and try and use Company1 as a variable it's not gong to work because nothing is in Company1. You declare it before that line of code but don't assign it a value until after that line of code I posted above.

The first five characters of "COMPANY1" is "COMPA". The first five characters of a variable with a NULL value is NULL (or possibly an error).
 

rainbows

Registered User.
Local time
Today, 11:15
Joined
Apr 21, 2017
Messages
425
I want to thank you all for helping me , taking out the quotes and taking the line down a few lines makes it work great thank you all steve
 

June7

AWF VIP
Local time
Today, 10:15
Joined
Mar 9, 2014
Messages
5,470
... Access helpfully converted it to a string and so you are seeing the first 5 characters of "company1", NOT the first 5 of some control or variable.
Access/VBA would not convert a variable name to a string. OP put the variable between quote marks.
 

rainbows

Registered User.
Local time
Today, 11:15
Joined
Apr 21, 2017
Messages
425
Code:
Private Sub Command437_Click()
Dim FILENAME As String
Dim strFullPath As Variant
    Dim folderpath As Variant
    Dim foldername As String
      Dim varfolder2 As String
      Dim company1 As String

 
      
    Dim varfolder As String
    
   If company = 1 Then company1 = "PPI-Engineering"
  
   If company = 2 Then company1 = "API-Engineering"

   If company = 3 Then company1 = "API-Capacitors"
 
   If company = 4 Then company1 = "temp"
  
             '   FILENAME = "ARNO" & "  " & Me.ARNO
  
               varfolder = DLookup("filepath", "company")
              
               FILENAME = Left(company1, 5) & "   " & "ARNO" & "  " & Me.ARNO
                  
               varfolder1 = varfolder & "\" & company1 & "\" & FILENAME & ".pdf"
                  
               Me.Dirty = False
            

DoCmd.OutputTo acOutputReport, "INDIVIDUAL ARNO", acFormatPDF, varfolder1


this now works

thanks to all
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:15
Joined
Oct 29, 2018
Messages
21,473
I want to thank you all for helping me , taking out the quotes and taking the line down a few lines makes it work great thank you all steve
Hi. Glad we could all assist. Good luck with your project.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:15
Joined
Feb 19, 2002
Messages
43,274
Access/VBA would not convert a variable name to a string.
Depends on where you are in the interface.. You type comapany1 in the QBE and Access will helpfully convert it to a string.
 

Users who are viewing this thread

Top Bottom