Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    jarhead8084 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2018
    Posts
    7

    Question New Member with an easy (I think) question Parens-quotes-doubles

    I have inherited a database that stored pictures in large binary data format. I have been able to successfully extract these images to a file folder giving them the primary key as filename and then .jpg, all is good...but, I would like to make the filename as such - firstname_lastname_primary key.jpg - I modified the SQL to pull the first and last names but have pulled most of my hair out trying to figure out the parentheses, single and double quotes. IDWCARDNUM is the primary key, I want to have - IDWFNAME underscore IDWLNAME underscore IDWCARDNUM.jpg or essentially Tom_Jones_1001.jpg

    This is the working line
    Code:
    mstream.SaveToFile "C:\Test\" & rs("IDWCARDNUM") & ".jpg", 2
    Something like this but not...
    Code:
    mstream.SaveToFile "C:\Test\" & rs("IDWFNAME" & "_" & "IDWLNAME" & "_" & "IDWCARDNUM") & ".jpg", 2
    Thank you all so much in advance, I have been away from Access for awhile, was never very good at quoting, need to study more and I am feeling the pain!

  2. #2
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    Try this;

    mstream.SaveToFile "C:\Test" & rs!IDWFNAME & "_" & rs!IDWLNAME & "_" & rs!IDWCARDNUM & ".jpg", 2

  3. #3
    jarhead8084 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2018
    Posts
    7
    Thanks for the quick response...sadly it says - write to file failed

  4. #4
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    Test the file path results to make sure it's formatting correctly using a message box or the immediate window

    Code:
    Dim strPath As String
    
    strpath = "C:\Test" & rs!IDWFNAME & "_" & rs!IDWLNAME & "_" & rs!IDWCARDNUM & ".jpg"
    
    msgBox strPath
    See if it's actually returning the file path you intend.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Somewhere along the line the backslash after c:\Test got lost. Reinstate it.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    jarhead8084 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2018
    Posts
    7
    Different error msg - Item cannot be found in the collection corresponding to the requested name or ordinal. Which I think is the error I was getting with all of the different variations of parens single and double quotes that I was trying. Also tried with the original working line of code and got the same error???

    Code:
    Dim strPath As String
    'strPath = "C:\Test" & rs!IDWFNAME & "_" & rs!IDWLNAME & "_" & rs!IDWCARDNUM & ".jpg"
    strPath = "C:\Test\" & rs("IDWCARDNUM") & ".jpg"
    MsgBox strPath

  7. #7
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    @Colin

    Thanks for pointing that out, i missed it. I must have mistakenly removed that in post #2

    @jarhead

    That may mean it can't find a field name you're trying to reference in the record set. Have you double checked that the field names are all correct?

  8. #8
    jarhead8084 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2018
    Posts
    7
    Ahh, I see, many thanks!!

  9. #9
    jarhead8084 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2018
    Posts
    7
    I feel certain that the field names are right - here is my SQL statement that preceeds
    Code:
    strsql = "SELECT IDWFNAME,IDWLNAME,IDWCARDNUM,IDWPhotofield1 FROM IDWSCHD WHERE IDWPhotofield1 is not null"
    Which I changed from the original
    Code:
    strsql = "SELECT IDWCARDNUM,IDWPhotofield1 FROM IDWSCHD WHERE IDWPhotofield1 is not null"

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    I hate to say the blindingly obvious but have you got two lines similar to this:

    Code:
    Dim rs As DAO.Recordset
    Set rs = CurrentDB.OpenRecordset(strSQL, OpenDynaset)
    Also have you tried testing this:
    mstream.SaveToFile "C:\Test" & rs!IDWCARDNUM & ".jpg", 2
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    jarhead8084 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2018
    Posts
    7
    Yes this works - mstream.SaveToFile "C:\Test" & rs!IDWCARDNUM & ".jpg", 2

    and...Here is the complete sub
    Code:
    Private Sub GetPhoto()
    db = "C:\Test\SCHD.mdb"
    Set cn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    Set mstream = CreateObject("ADODB.Stream")
    mstream.Type = 1
    cn.Open "Provider = Microsoft.Jet.OLEDB.4.0; " & "Data Source =" & db
    strsql = "SELECT IDWFNAME,IDWLNAME,IDWCARDNUM,IDWPhotofield1 FROM IDWSCHD WHERE IDWPhotofield1 is not null"
    
    rs.Open strsql, cn
    Do While Not rs.EOF
    mstream.Open
    mstream.Write rs("IDWPhotofield1")
    mstream.SaveToFile "C:\Test\" & rs!IDWCARDNUM & ".jpg", 2
    mstream.Close
    rs.MoveNext
    Loop
    End Sub

  12. #12
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Just realised I also left out the backslash after Test in my last post !!!
    As you did in the intro to your latest post - its fated

    Try this as a simpler alternative using a DAO recordset:

    Code:
    Private Sub GetPhoto()
    
    Dim rs As DAO.Recordset
    strsql = "SELECT IDWFNAME,IDWLNAME,IDWCARDNUM,IDWPhotofield1 FROM IDWSCHD WHERE IDWPhotofield1 is not null"
    
    Set rs=CurrentDB.OpenRecordset(strSQL,OpenDynaset)
    
    With rs
         .MoveFirst
          DoUntil .EOF
         .Edit
          !IDWPhotofield="C:\Test\" & !IDWFNAME & "_" & !IDWLNAME & "_" & !IDWCARDNUM & ".jpg"
          .Update
          MoveNext
          Loop 
          .Close
    End With
    
    Set rs = Nothing
    
    End Sub
    Or much easier still, just use an UPDATE query instead of a recordset:
    Code:
    UPDATE IdwSchd SET IdwSchd.IdwPhotoField1 = "C:\Test\" & [IDWFNAME] & "_" & [IDWLNAME] & "_" & [IDWCARDNUM] & ".jpg"WHERE (((IdwSchd.IdwPhotoField1) Is Not Null));
    This will be FAR faster than a recordset especially if you have a lot of records to update
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Saving calculated data usually unnecessary. If the path is built from existing data, just calc when needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    True and I thought about making the same point.
    However, in this case, if the file path is fixed and will be referenced regularly, I think it's valid to store it using the simplest method possible.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  15. #15
    jarhead8084 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2018
    Posts
    7
    For anyone who is interested - this slight addition and code alteration to the sub accomplished what I was looking for...
    Code:
    Dim fnam As String
    fnam = "C:\Test\" & rs!IDWFNAME & "_" & rs!IDWLNAME & "_" & rs!IDWCARDNUM & ".jpg"
    mstream.SaveToFile fnam, 2
    gotta love the simplicity

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Easy Question about Many to Many
    By hoodoo in forum Access
    Replies: 17
    Last Post: 09-22-2015, 10:05 AM
  2. Easy question
    By fyes in forum Programming
    Replies: 1
    Last Post: 12-20-2011, 12:08 AM
  3. Probably a very easy question
    By Ext1jdh in forum Queries
    Replies: 4
    Last Post: 08-02-2011, 12:26 PM
  4. Easy Question Need Help With
    By jdusaf in forum Access
    Replies: 1
    Last Post: 03-23-2011, 11:33 AM
  5. Easy question
    By Danzig in forum Access
    Replies: 11
    Last Post: 10-28-2010, 06:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums