How to link Drawings in Access 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • greeni91
    New Member
    • Nov 2009
    • 61

    How to link Drawings in Access 2003

    I am currently trying to fix up my old database and I have hit a bit of a snag...

    I am trying to link a drawing (bitmap image) to a form.

    I have set up a table with the Path to the image in one column and the part number it corresponds to in the other.

    On my main form I have a button next to the part number field which I want to use to display the images in another form. It copies the part number from the main form and pastes it to the part number in the "Drawing" form.

    I tried to use a DLookup to display the image but to no avail.

    I have also tried the Microsoft way of doing things but their explanations of what needs to be changed from the template is rather s**t.
    Last edited by Niheel; Jun 1 '10, 10:42 AM. Reason: spelling
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by greeni91
    I am currently trying to fix up my old database and I have hit a bit of a snag...

    I am trying to link a drawing (bitmap image) to a form.

    I have set up a table with the Path to the image in one column and the part number it corresponds to in the other.

    On my main form I have a button next to the part number field which I want to use to display the images in another form. It copies the part number from the main form and pastes it to the part number in the "Drawing" form.

    I tried to use a DLookup to display the image but to no avail.

    I have also tried the Microsoft way of doing things but their explanations of what needs to be changed from the template is rather s**t.
    Just subscribing, will return later. Is Part Number a String or Number?

    Comment

    • greeni91
      New Member
      • Nov 2009
      • 61

      #3
      Originally posted by ADezii
      Just subscribing, will return later. Is Part Number a String or Number?
      The Part Number is set as a string as it begins with 2 letters, e.g. AG55470.

      /Sandy

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        1. Open the 2nd Form via the OpenForm() Method, and pass the Part Number via the OpenArgs Property (PartNum should be Required):
          Code:
          DoCmd.OpenForm "frmImages", acNormal, , , acFormEdit, acWindowNormal, Me![txtPartNum]
        2. In the Open() Even of the 2nd Form:
          • Copy the Part Number to the Text Box on the 2nd Form.
          • Use the DLookup() Function to retrieve the associated Path for the given Part Number.
          • If the Path is NULL, get outta Dodge!
          • If the Image Path is invalid, get outta Dodge!
          • If all is well, set the Picture Property of the Image Control to the Value retrieved from DLookup().
        3. Replace with your own Control/Form Names.
        4. Any questions, feel free to ask.
          Code:
          Private Sub Form_Open(Cancel As Integer)
          Dim varPictureToLoad
          
          Me![txtPartNum] = Me.OpenArgs
          
          varPictureToLoad = DLookup("[Path]", "tblImages", "[PartNum] = '" & Me.OpenArgs & "'")
          
          If IsNull(varPictureToLoad) Then
            MsgBox "No Picture to Load", vbExclamation, "No Value in Field"
              DoCmd.Close
          Else
            If Dir$(varPictureToLoad) <> "" Then
              Me![imgTest].Picture = varPictureToLoad
            Else
              MsgBox varPictureToLoad & " is not a valid Path", vbExclamation, "Invalid Path"
                DoCmd.Close
            End If
          End If
          End Sub

        Comment

        • greeni91
          New Member
          • Nov 2009
          • 61

          #5
          Originally posted by ADezii
          1. Open the 2nd Form via the OpenForm() Method, and pass the Part Number via the OpenArgs Property (PartNum should be Required):
            Code:
            DoCmd.OpenForm "frmImages", acNormal, , , acFormEdit, acWindowNormal, Me![txtPartNum]
          2. In the Open() Even of the 2nd Form:
            • Copy the Part Number to the Text Box on the 2nd Form.
            • Use the DLookup() Function to retrieve the associated Path for the given Part Number.
            • If the Path is NULL, get outta Dodge!
            • If the Image Path is invalid, get outta Dodge!
            • If all is well, set the Picture Property of the Image Control to the Value retrieved from DLookup().
          3. Replace with your own Control/Form Names.
          4. Any questions, feel free to ask.
            Code:
            Private Sub Form_Open(Cancel As Integer)
            Dim varPictureToLoad
            
            Me![txtPartNum] = Me.OpenArgs
            
            varPictureToLoad = DLookup("[Path]", "tblImages", "[PartNum] = '" & Me.OpenArgs & "'")
            
            If IsNull(varPictureToLoad) Then
              MsgBox "No Picture to Load", vbExclamation, "No Value in Field"
                DoCmd.Close
            Else
              If Dir$(varPictureToLoad) <> "" Then
                Me![imgTest].Picture = varPictureToLoad
              Else
                MsgBox varPictureToLoad & " is not a valid Path", vbExclamation, "Invalid Path"
                  DoCmd.Close
              End If
            End If
            End Sub
          I have tried your code it is so close to working it is unreal. I am having a small problem when defining the Me.OpenArgs object.

          When I run the code it gives me the error:

          Run-time error '2448':
          You can't assign a value to this object

          I have remembered and changed all form names and control names in the code and when in debug mode it highlights

          Me![PartNumber] = Me.OpenArgs.

          When I scroll over this comment it says each half equals the part number from the 1st form, so I can't see the problem.

          Hope you can help

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by greeni91
            I have tried your code it is so close to working it is unreal. I am having a small problem when defining the Me.OpenArgs object.

            When I run the code it gives me the error:

            Run-time error '2448':
            You can't assign a value to this object

            I have remembered and changed all form names and control names in the code and when in debug mode it highlights

            Me![PartNumber] = Me.OpenArgs.

            When I scroll over this comment it says each half equals the part number from the 1st form, so I can't see the problem.

            Hope you can help
            1. Is that a Comma or Period that I see after OpenArgs? If so, remove it.
            2. Did you place this Code in the Open() Event of the 2nd Form, the one containing the Image Control?

            Comment

            • greeni91
              New Member
              • Nov 2009
              • 61

              #7
              Sorry about that... The period was because I had reached the end of my sentence. Grammar got the best of me.

              I have pasted the code to the OnOpen() event on the Drawing form.

              Comment

              • greeni91
                New Member
                • Nov 2009
                • 61

                #8
                This is a copy of the amended code if it makes it easier to see what I'm trying to do.

                Code:
                Private Sub Form_Open(Cancel As Integer)
                Dim varPictureToLoad
                 
                Me![PartNumber] = Me.OpenArgs
                 
                varPictureToLoad = DLookup("[Drawing]", "NewParts", "[Part Number] = '" & Me.OpenArgs & "'")
                 
                If IsNull(varPictureToLoad) Then
                  MsgBox "No Picture to Load", vbExclamation, "No Value in Field"
                    DoCmd.Close
                Else
                  If Dir$(varPictureToLoad) <> "" Then
                    Me![imgTest].Picture = varPictureToLoad
                  Else
                    MsgBox varPictureToLoad & " is not a valid Path", vbExclamation, "Invalid Path"
                      DoCmd.Close
                  End If
                End If
                End Sub

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Originally posted by greeni91
                  This is a copy of the amended code if it makes it easier to see what I'm trying to do.

                  Code:
                  Private Sub Form_Open(Cancel As Integer)
                  Dim varPictureToLoad
                   
                  Me![PartNumber] = Me.OpenArgs
                   
                  varPictureToLoad = DLookup("[Drawing]", "NewParts", "[Part Number] = '" & Me.OpenArgs & "'")
                   
                  If IsNull(varPictureToLoad) Then
                    MsgBox "No Picture to Load", vbExclamation, "No Value in Field"
                      DoCmd.Close
                  Else
                    If Dir$(varPictureToLoad) <> "" Then
                      Me![imgTest].Picture = varPictureToLoad
                    Else
                      MsgBox varPictureToLoad & " is not a valid Path", vbExclamation, "Invalid Path"
                        DoCmd.Close
                    End If
                  End If
                  End Sub
                  Let me see your OpenForm() Statement where you are actually passing the OpenArgs Value.

                  Comment

                  • greeni91
                    New Member
                    • Nov 2009
                    • 61

                    #10
                    Originally posted by ADezii
                    Let me see your OpenForm() Statement where you are actually passing the OpenArgs Value.
                    What do you mean.... I only used both pieces of code that you gave me and that's all.

                    I don't think I have anything passing my OpenArgs value. The only thing is the code above that has OpenArgs mentioned in it.

                    Comment

                    • ADezii
                      Recognized Expert Expert
                      • Apr 2006
                      • 8834

                      #11
                      Originally posted by greeni91
                      What do you mean.... I only used both pieces of code that you gave me and that's all.

                      I don't think I have anything passing my OpenArgs value. The only thing is the code above that has OpenArgs mentioned in it.
                      That explains it. You need to Open the 2nd Form with the Part Number passed within the OpenArgs Property. I did explain this to you in Post #4, Item #1. I'll repeat the code again, make you own substitutions for Form Name and Text Box Name containing the Part Number:
                      Code:
                      DoCmd.OpenForm "frmImages", acNormal, , , acFormEdit, acWindowNormal, Me![txtPartNum]

                      Comment

                      • greeni91
                        New Member
                        • Nov 2009
                        • 61

                        #12
                        Yes I already have this code entered, but I have entered it to the Command button on the main form. Would this explain the problem??

                        The code is as follows:

                        Code:
                          
                        Private Sub Drawing_Click()
                        DoCmd.OpenForm "Drawing", acNormal, , , acFormEdit, acWindowNormal, Me![PartNo]
                        End Sub
                        I am using this Command button to open the 2nd form and thought that was where you wanted the code.... Where exactly do you want the code to be placed (main form or second form) and what control will I link it to??

                        Comment

                        • ADezii
                          Recognized Expert Expert
                          • Apr 2006
                          • 8834

                          #13
                          Originally posted by greeni91
                          Yes I already have this code entered, but I have entered it to the Command button on the main form. Would this explain the problem??

                          The code is as follows:

                          Code:
                            
                          Private Sub Drawing_Click()
                          DoCmd.OpenForm "Drawing", acNormal, , , acFormEdit, acWindowNormal, Me![PartNo]
                          End Sub
                          I am using this Command button to open the 2nd form and thought that was where you wanted the code.... Where exactly do you want the code to be placed (main form or second form) and what control will I link it to??
                          Yes I already have this code entered, but I have entered it to the Command button on the main form. Would this explain the problem??
                          No
                          Can you Upload the Database, so I can take a look at it?

                          Comment

                          • greeni91
                            New Member
                            • Nov 2009
                            • 61

                            #14
                            I tried to upload the database but Bytes.com said it is an invalid file extension... Could you give me an email address to send the database to you. Send it to me in a private email please so your addess isn't posted on the thread.

                            /Sandy

                            Comment

                            Working...