By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 915 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

file attachment on MS Access 2007

ddtpmyra
100+
P: 333
Need to know how to do the vba coding on attaching the file

code
Private Sub Command_Click()
Dim rs1 As Recordset
Set rs1 = CurrentDb.OpenRecordset("cmr_filestorage")
rs1.AddNew
Me.author = rs1.Fields("author")
Me.requestor = rs1.Fields("requestor")
Me.deadline = rs1.Fields("deadline")
Me.category = rs1.Fields("category")
Me.descripton = rs1.Fields("description")
Me.file = rs1.Fields("file")

rs1.Update
rs1.Close

MsgBox "New record added"
End Sub

Problem
I can do the file upload to the user interface but when I hit the button to save the new records error message "Object does'nt support this method" and it's pointing to:
Me.file = rs1.Fields("file")

Question
Somebody can show me how to handle this error im kinda new on ms 2007

thanks,
DM
Sep 22 '08 #1
Share this Question
Share on Google+
7 Replies


DonRayner
Expert 100+
P: 489
Need to know how to do the vba coding on attaching the file

code
Private Sub Command_Click()
Dim rs1 As Recordset
Set rs1 = CurrentDb.OpenRecordset("cmr_filestorage")
rs1.AddNew
Me.author = rs1.Fields("author")
Me.requestor = rs1.Fields("requestor")
Me.deadline = rs1.Fields("deadline")
Me.category = rs1.Fields("category")
Me.descripton = rs1.Fields("description")
Me.file = rs1.Fields("file")

rs1.Update
rs1.Close

MsgBox "New record added"
End Sub

Problem
I can do the file upload to the user interface but when I hit the button to save the new records error message "Object does'nt support this method" and it's pointing to:
Me.file = rs1.Fields("file")

Question
Somebody can show me how to handle this error im kinda new on ms 2007

thanks,
DM
If you're adding a new record to the table you need to change these lines

Me.author = rs1.Fields("author")....should be rs1.fields("author") = me.author.value
Me.requestor = rs1.Fields("requestor")...... same change as above
Me.deadline = rs1.Fields("deadline")......etc
Me.category = rs1.Fields("category").....etc
Me.descripton = rs1.Fields("description")......etc
Me.file = rs1.Fields("file")....etc
Sep 23 '08 #2

NeoPa
Expert Mod 15k+
P: 31,342
As Don says, you're moving the data the wrong way. You need to move it from the form (Me.) to the record buffer (rs1.).

Having said all that, this is really a quite unnecessarily complicated way to handle something that Access forms do for you anyway, without any work required.

Have a look at some of the wizards.
Sep 23 '08 #3

ddtpmyra
100+
P: 333
Everythings works fine except when I'm saving the file attachment
I tried this but does'nt work

rs.Fields("file") = Me.file.Filename.Value
rs.Fields("file") = Me.file.FileType.Value
rs.Fields("file") = Me.file.FileURL.Value

I need more help on this please.
Sep 23 '08 #4

NeoPa
Expert Mod 15k+
P: 31,342
...
I need more help on this please.
I suggest you pay some more attention to what's already posted then. Simply ignoring responses is not likely to win you too much help.
Sep 23 '08 #5

ddtpmyra
100+
P: 333
NeoPa,

It's the same problem on file attachment if you look on my first post.

I can do the file upload to the user interface but when I hit the button to save the new records error message "Object does'nt support this method" and it's pointing to:
Me.file = rs1.Fields("file")
Sep 23 '08 #6

DonRayner
Expert 100+
P: 489
Everythings works fine except when I'm saving the file attachment
I tried this but does'nt work

rs.Fields("file") = Me.file.Filename.Value
rs.Fields("file") = Me.file.FileType.Value
rs.Fields("file") = Me.file.FileURL.Value

I need more help on this please.
It needs to be "rs.Fields("file") = me.file.value". Also make sure that you don't have a typo for the field name in your table or in the control name. Add a msgbox "msgbox me.file.value" at the beginning of your sub to see what value you're trying to add.

Try this code and see how it works

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command_Click()
  2. On error goto ErrorPoint
  3.  
  4. Dim db1 as dao.databae, rs1 As dao.Recordset
  5. Set db1 = CurrentDb
  6. set rs1 = db1.OpenRecordset("cmr_filestorage")
  7.  
  8. rs1.AddNew
  9.  
  10. rs1!author = me.author.value
  11. rs1!requestor = me.requestor.value
  12. rs1!deadline = me.deadline.value
  13. rs1!category = me.category.value
  14. rs1!description = me.description.value
  15. rs1!file = me.file.value
  16.  
  17. rs1.Update
  18. rs1.Close
  19.  
  20. set rs1 = nothing
  21. set db1 = nothing
  22.  
  23. MsgBox "New record added"
  24. ExitPoint:
  25. Exit Sub
  26.  
  27. ErrorPoint:
  28. msgbox err.descripton & "  Error# " & err.number
  29. Resume ExitPoint
  30.  
  31. End Sub
  32.  
You will need to make sure that you Microsoft DAO referanced for this code to work.
Sep 23 '08 #7

NeoPa
Expert Mod 15k+
P: 31,342
NeoPa,

It's the same problem on file attachment if you look on my first post.
I wasn't asking for the question to be repeated. I was merely wondering at the fact that you don't seem to have noticed some of the comments already posted.

This whole issue is only a problem because you are trying to bark yourself, when Access makes a perfectly good dog. Check out post #3.

Post #2 answers your problem if you insist on continuing to try to code, what is already built into the functionality of Access forms, yourself.
Sep 23 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.