Adding subform entries

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ScottM
    New Member
    • Mar 2008
    • 2

    Adding subform entries

    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.

    [code=vb]Dim objCMDlg As Object
    Dim strFileName As String
    Dim strHelpFile As String
    Dim strMethod As String
    Dim FileTitle As String
    Dim FilePathName As String
    Dim sAttachment As String

    On Error GoTo HandleErr

    strMethod = "SHOWOPEN"
    Set objCMDlg = Forms![ECOForm].ComDialogAttac hment
    objCMDlg.Cancel Error = True

    With objCMDlg
    Select Case UCase(strMethod )

    Case "SHOWOPEN"
    ' File Open dialog box
    .Filename = "*.*"
    .InitDir = "\\network location"
    .Filter = "All File(*.*)|*.*"
    .ShowOpen
    If Len(.Filename) <> 0 Then
    FileTitle = .FileTitle
    FilePathName = .Filename
    sHyperlink = "#" & FilePathName & "#"
    End If
    End Select
    End With[/code]
    Last edited by Stewart Ross; Mar 17 '08, 08:34 PM. Reason: Added code tags round VB code
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    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].ComDialogAttac hment returns?
    • What is really a need to get the object in such a bizarre way?


    Regards,
    Fish

    Comment

    • ScottM
      New Member
      • Mar 2008
      • 2

      #3
      All that code does is open up a common dialog box and allow me to choose a file to add as an attachment.

      Comment

      Working...