Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    ck4794 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    80

    invalid argument

    i can open a file dialog with my button, and it call the add attachment code, and in there is an invalid argument that i don't know how to fix. please see attached screen shot.



    june7, if you're out there, i know we've discussed this at length but i don't think we ever came to a conclusion on this part...Click image for larger version. 

Name:	invalidargument.jpg 
Views:	20 
Size:	253.7 KB 
ID:	14276

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I don't know anything about .LoadFromFile but assuming that is correct...... What does strFilePath = when you hover over it in debug mode?

  3. #3
    ck4794 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    80
    Quote Originally Posted by ItsMe View Post
    I don't know anything about .LoadFromFile but assuming that is correct...... What does strFilePath = when you hover over it in debug mode?
    strfilepath=""

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    In order for that line of code to work you are going to need to assign the path of the file you are trying to attach to strFilePath.

    It does not seem that your Command0_Click event is assigning the path to strFilePath when it calls the sub procedure.

  5. #5
    ck4794 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    80
    Yea I just don't know what to do about it. That level of code is a bit above my head.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by ck4794 View Post
    Yea I just don't know what to do about it. That level of code is a bit above my head.
    Maybe you can start by copying and then pasting your code for the click event here. It helps if you use the advanced posting options and enclose your code with code tags. If you click "Go Advanced" you can insert the code tags in your post by clicking the hashtag icon (#)

    Code:
    Your code should be inside the code tags

  7. #7
    ck4794 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    80
    Code:
    Private Sub Command0_Click() Dim fDialog As Office.FileDialog
       Dim varFile As Variant
       Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
       With fDialog
          ' Allow the user to make multiple selections in the dialog box.
          .AllowMultiSelect = False
              
          ' Set the title of the dialog box.
          .title = "Select a File"
    
    
          ' Clear out the current filters, and then add your own.
          .Filters.Clear
          .Filters.Add "All Files", "*.*"
    
    
          ' Show the dialog box. If the .Show method returns True, the
          ' user picked at least one file. If the .Show method returns
          ' False, the user clicked Cancel.
          If .Show = True Then
             ' Loop through each file that is selected and then add it to the list box.
          Dim rst As DAO.Recordset
                Const strTable = "tblImages"
                Const strField = "Image"
                Set rst = CurrentDb.OpenRecordset(strTable)
                rst.AddNew
                AddAttachment rst, strField, varFile
                rst.Update
                rst.MoveLast
                rst.Close
          Else
             MsgBox "You clicked Cancel in the file dialog box."
          End If
       End With
    End Sub
    here's my on click event but that doesn't seem to be a problem. it's just opening a file dialog box and all that seems to be working well. it's directly after i select the file click "OK" in my file dialog the error occurs.

    here's the add attachment code i'm using in the general declarations. this is where my issue is coming.
    Code:
    Sub AddAttachment(ByRef rstCurrent As DAO.Recordset, ByVal strFieldName As String, ByVal strFilePath As String)
        Const m_strFieldFileName As String = "FileName" ' The name of the attached file
        Const m_strFieldFileType As String = "FileType" ' The attached file's extension
        Const m_strFieldFileData As String = "FileData" ' The binary data of the file
        Const CALLER = "AddAttachment"
        Dim rstChild  As DAO.Recordset2
        Dim fldAttach As DAO.Field2
    
    
        If Dir(strFilePath) = "" Then ' the specified file does not exist!
            MsgBox "The specified input file does not exist: " & vbCrLf & strFilePath, vbCritical, "File not found"
            Exit Sub
        End If
    
    
        Set rstChild = rstCurrent.Fields(strFieldName).Value ' the .Value for a complex field returns the underlying Recordset.
        rstChild.AddNew ' add a new row to the child Recordset
        Set fldAttach = rstChild.Fields(m_strFieldFileData) ' set the DAO.Field2 object to the field that holds the binary data.
        fldAttach.LoadFromFile strFilePath ' store the file's contents in the new row.
        rstChild.Update ' commit the new row.
        rstChild.Close ' close the child Recordset.
    
    
        Exit Sub
    End Sub

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Let me see if I can find the other thread and get more info. There are some missing pieces here.

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    It seems you may have a general module where a user defined function is. Were you able to compile VBA via the debugger as June7 suggested? What happens when you compile database?

    Please do not try to execute the code and then say the error is here. Specificaly, what happens when you go Debugger and then Compile Database?

  10. #10
    ck4794 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    80
    Quote Originally Posted by ItsMe View Post
    It seems you may have a general module where a user defined function is. Were you able to compile VBA via the debugger as June7 suggested? What happens when you compile database?

    Please do not try to execute the code and then say the error is here. Specificaly, what happens when you go Debugger and then Compile Database?
    i may need some guidance on this. i clicked the button, got the error, went into debug, went to debug>compile, and nothing happened...

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    You will be working from within the VBA editor. You do not need any forms open. Do not execute any code from a form. Do not compile while the debugger is running.


    Just below this line

    Private Sub Command0_Click() Dim fDialog As Office.FileDialog

    paste this in the next line, by itself in its own line of code.

    msgbox "Hello World"

    From there, save your work from within the VBA editor. Use the drop down from the toolbar menu at the top of the VBA editor. From debugger, select Compile Database or Compile.... whatever the Compile thing says

  12. #12
    ck4794 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    80
    followed your instructions to the T, nothing happened. what should be happening?

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I looked into your code a little bit. Do you believe that pasting two different procedures from two different websites into your db is, somehow, going to acomplish something?

  14. #14
    ck4794 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    80
    Quote Originally Posted by ItsMe View Post
    I looked into your code a little bit. Do you believe that pasting two different procedures from two different websites into your db is, somehow, going to acomplish something?
    Well yes I do believe that, or else why would I? Judging from the condescending nature of the question you don't.

    It got me half way there. I can open the file dialog from the click of the button. The part that's not working is inserting the file i pick into the attachment field in a certain table. From the way I read it, the on click portion i copied and pasted will open the file dialog, but doesn't necessarily do anything with the file. The addattachment portion i copied and pasted, will insert the attachment, but has no method of choosing the attachment. And my question here is to marry them together. If you have a better method I'm all ears... Then END goal is that i want to bypass the native attachment manager, and only allow the user to upload one file at a time, and have one record for one attachment. The rest I should be able to work out for myself, as far as relating the records to other tables and what not.

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by ck4794 View Post
    Well yes I do believe that, or else why would I? Judging from the condescending nature of the question you don't.
    Condescending or not I need to understand what your expectations are. It was a legitimate question. I spent a small amopunt of time reading your previous thread and then this thread. The impression I had was you don't understand what the code is doing or needs to do. Thankfully, for both of us, you chose to answer truthfully.

    I created a DB to test the automated addattach thing. I got it working. I will work on the second part using the picker. I will upload it here after a bit. I have to take the time to read the code, decipher it, and understand what it is doing.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Invalid Argument Error Message
    By kcochran130 in forum General Chat
    Replies: 1
    Last Post: 05-30-2013, 08:20 AM
  2. Invalid Procedure Call or Argument
    By Trojnfn in forum Access
    Replies: 2
    Last Post: 10-29-2012, 01:44 PM
  3. Invalid argument
    By wharting in forum Import/Export Data
    Replies: 4
    Last Post: 10-19-2011, 11:49 PM
  4. Invalid Argument on update query in v2010
    By DropDeadDavey in forum Queries
    Replies: 2
    Last Post: 07-28-2011, 06:27 PM
  5. Invalid Argument Error
    By koper in forum Access
    Replies: 2
    Last Post: 06-14-2010, 11:22 AM

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