Results 1 to 5 of 5
  1. #1
    johnnyBQue is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    33

    Attachment data type and Control question using VBA

    New to writing code, and I'm having difficulty figuring out attachments (seems others are too). What I'm looking to do is bring up a set of attachments when performing a search on an employees name or ID. I'm having issues because VB doesn't seem to want to work with attachment controls or fields too well and my ignorance isn't helping. Where I've used (example)



    CurrentDb.Execute "UPDATE recEmpJD " & _
    " Set EmpID=" & Me.txtID & _
    "' HireDate='" & ME,txtHireDate & "'" & _
    "' Depart='" & Me.cboDepart & "'" & _

    I can't seem to figure out what identifier works for attachment control "att" ?? or am I totally wet and need to address attachments in a different manner? Seems like the attachment control (type) isn't compatible when used in a string with other field/data types.

    any suggestion would be take most welcome

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Not sure what an attachment control is, but are you talking about an attachment FIELD?
    If so, you treat the field as a recordset. (a recset in a recset)

    Code:
    Public Sub OpenAttach()
    Dim att
    Dim rst
    Dim i As Integer
    Set rst = CurrentDb.OpenRecordset("qsAtt")
    Set att = rst.Fields("attachFld").Value   'it a recordset
    With att
       While Not .EOF
               'Debug.Print att.Fields(2).Name, att.Fields(2).Value
            .Fields("FileData").SaveToFile "\\myserver\myfolder\rst.xlsx"
          .MoveNext
       Wend
    End With
    
    Set rst = Nothing
    Set att = Nothing
    End Sub

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

  4. #4
    johnnyBQue is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    33
    I'm sorry guys but it looks like I'm not explaining myself correctly. The code below Works! very well...
    Now what I'm having problems is how to enter an attachment field into code thats similar to below... Now I was told to treat it as a RS so I figure I can't use somthing like ", Resume='" & Me.AttResume & "'" & _ becasue this doesn't identify the attachment field as a attachment field? even though I name it and so forth...

    thanks for your patience...

    Private Sub cmdAdd_Click()
    'when we click on button Add there are two options
    '1. for insert
    '2. for update
    If Me.txtID.Tag & "" = "" Then
    'This is for insert new
    'add data to table
    CurrentDb.Execute "INSERT INTO recEmpPR(EmployeeID, LastName, MiddleInitial, FirstName, Gender, BirthDate, HomePhone, MaritalStatus, Address, City, State, ZIPCode) " & _
    " VALUES(" & Me.txtID & ",'" & Me.txtFirstName & "','" & Me.txtMI & "','" & Me.txtLastname & "','" & Me.cboGender & "','" & Me.txtBirthDate & "','" & Me.txtPhNumber & "','" & Me.cboMaritalStatus & "','" & Me.txtAddress & "','" & Me.txtCity & "','" & Me.txtState & "','" & Me.txtZipCode & "')"
    Else
    'otherwise (Tag of txtID store the id of employee to be modified)
    CurrentDb.Execute "UPDATE recEmpPR " & _
    " Set EmployeeID=" & Me.txtID & _
    ", FirstName='" & Me.txtFirstName & "'" & _
    ", MiddleInitial='" & Me.txtMI & "'" & _
    ", LastName='" & Me.txtLastname & "'" & _
    ", Gender='" & Me.cboGender & "'" & _
    ", BirthDate='" & Me.txtBirthDate & "'" & _
    ", HomePhone='" & Me.txtPhNumber & "'" & _
    ", MaritalStatus='" & Me.cboMaritalStatus & "'" & _
    ", Address='" & Me.txtAddress & "'" & _
    ", City='" & Me.txtCity & "'" & _
    ", State='" & Me.txtState & "'" & _
    ", ZIPCode='" & Me.txtZipCode & "'" & _
    " WHERE EmployeeID=" & Me.txtID.Tag
    End If

    'Clear Form
    cmdClear_Click
    'referesh data in list on form
    subfrmEmpPR.Form.Requery
    End Sub

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    An attachment field is a type of multi-value field. Multi-value fields cannot be treated the same as other fields. As ranman pointed out, must open the attachment field as a recordset. It is considered a child or sub recordset.

    1. INSERT or UPDATE record for the normal type fields

    2. run more code to UPDATE the attachment multi-value field to add/edit content
    Review https://www.accessforums.net/program...vba-21259.html

    I NEVER use multi-value fields for normal data. I have used attachment field for embedding images into table only once - a very small db used once to generate a report then abandoned.
    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.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Basic question on table design data type: lookup
    By drspanda@gmaill.com in forum Access
    Replies: 1
    Last Post: 07-17-2014, 07:56 PM
  2. working with attachment field type
    By ricky99 in forum Forms
    Replies: 8
    Last Post: 09-16-2012, 03:59 AM
  3. Replies: 3
    Last Post: 07-21-2012, 10:20 PM
  4. Control Source Data Question
    By walt44 in forum Forms
    Replies: 3
    Last Post: 12-13-2011, 12:56 PM
  5. Attachment data type INSERT INTO not working
    By LouisLouis in forum Programming
    Replies: 0
    Last Post: 09-27-2009, 02:23 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