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

Adding subform entries

P: 2
Hi,

I am an experienced VB6 programmer but a novice when it comes to MS Access. I have a form for ECO's (Engineering Change Orders) based on the table ECO, and in it I created a subform that is linked to a table called Attachments. The attachments are files related to the ECO. I used the wizard to do the work of adding the subform. So far, so good. As I cycle through the ECO's, the subform populates with the file attachments.

What I need to do is to be able to add new attachments or delete existing ones. I can delete existing ones by simply selecting the row in the attachments subform and hitting Delete, although this seems a little dangerous. What is the easiest way to add a new attachment? By the way, my attachment table includes the file title and a hyperlink that includes the full path name and file title. I have code to locate another file, as shown below. It's what I do next that has me wondering.

Expand|Select|Wrap|Line Numbers
  1. Dim objCMDlg As Object
  2. Dim strFileName As String
  3. Dim strHelpFile As String
  4. Dim strMethod As String
  5. Dim FileTitle As String
  6. Dim FilePathName As String
  7. Dim sAttachment As String
  8.  
  9. On Error GoTo HandleErr
  10.  
  11. strMethod = "SHOWOPEN"
  12. Set objCMDlg = Forms![ECOForm].ComDialogAttachment
  13. objCMDlg.CancelError = True
  14.  
  15. With objCMDlg
  16. Select Case UCase(strMethod)
  17.  
  18. Case "SHOWOPEN"
  19. ' File Open dialog box
  20. .Filename = "*.*"
  21. .InitDir = "\\network location"
  22. .Filter = "All File(*.*)|*.*"
  23. .ShowOpen
  24. If Len(.Filename) <> 0 Then
  25. FileTitle = .FileTitle
  26. FilePathName = .Filename
  27. sHyperlink = "#" & FilePathName & "#"
  28. End If
  29. End Select
  30. End With
Mar 17 '08 #1
Share this Question
Share on Google+
2 Replies


FishVal
Expert 2.5K+
P: 2,653
Hi, ScottM.

Generally you have at least two ways to add new record:
  • via form positioned to new record
  • direct adding new record to a relevant table(s) using SQL or DAO/ADO recordsets

But you code looks somewhat confusing.
  • In what context it is being executed?
  • Object of what class does [ECOForm].ComDialogAttachment returns?
  • What is really a need to get the object in such a bizarre way?

Regards,
Fish
Mar 18 '08 #2

P: 2
All that code does is open up a common dialog box and allow me to choose a file to add as an attachment.
Mar 18 '08 #3

Post your reply

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