Results 1 to 9 of 9
  1. #1
    cg1465 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    8

    Command Button to Find .doc file

    Thanks in advance!

    I've created a command button to find a .doc file. This file has a path that includes the record's phone number in the file name. I'm using this code to try and pull the file, but debugger says it can't find the file.

    Private Sub Command155_Click()

    Dim oApp As Object
    Set oApp = CreateObject("Word.Application")
    oApp.Visible = True
    AppActivate oApp
    oApp.Documents.Open FileName:=FilLoc & "C:\FirstUSA\Prospects\ & forms![FirstUSA].[Phone1] & .doc", readonly:=readonly
    Set oApp = Nothing
    End Sub



    I need this to pull the current record I'm viewing. In other words, insert the record's phone into the path that I'm currently viewing.

    Thanks!

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    are you sure that Access uses this code:
    Code:
    FileName:=
    I thought those syntax were restricted to excel and word only? might want to check that.

    also, use DIR() to check and see if the file is there first:
    Code:
    if DIR( _
       "C:\FirstUSA\Prospects\ '" & forms![FirstUSA].[Phone1] & "'.doc") = 0 then
          msgbox "file not found"
    else
       'DO WHATEVER YOU NEED TO
    end if
    I changed your concatenation too. I think that is incorrect for strings.

  3. #3
    cg1465 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    8
    Thanks Adam. Much appreciated. It gives me a data mismatch type error, however. Any ideas?

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by cg1465 View Post
    Thanks Adam. Much appreciated. It gives me a data mismatch type error, however. Any ideas?
    could be any number of things. May be able to help you if you give us the:

    *data type of the form control
    *data type of the field it is bound to
    *line of code where the error is thrown

    also...like almost every function in Access, the "()" enclosures may or may not be accepted. As a general rule, they are accepted after the VBA operation IF the first argument is a variable of any kind. In any other situation, they are not. It seems to depend on how Access is feeling on that particular day...

    That is not 100% true, only my experience with this rather annoying requirement of Basic.

  5. #5
    cg1465 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    8
    hmmm...all text format. The debugger picks up this line:

    If Dir( _
    "C:\FirstUSA\Prospects\ '" & Forms![FirstUSA].[Phone1] & "'.doc") = 0 Then

    I'm not really code savvy, but seems like it should work...aaarrrg.

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by cg1465 View Post
    If Dir( _
    "C:\FirstUSA\Prospects\ '" & Forms![FirstUSA].[Phone1] & "'.doc") = 0 Then
    .
    did you try what I already mentioned????
    Code:
     if Dir "C:\FirstUSA\Prospects\ '" & Forms![FirstUSA].[Phone1] & "'.doc" = 0 then
    Just noticed this too: Forms![FirstUSA].[Phone1]

    No consistency. Try either Forms![FirstUSA]![Phone1] or Forms("FirstUSA").Controls("Phone1")

    Is that a phone number? does it have a mask? what data type is it in the form control and the field of the table? These are all potential bugs.

  7. #7
    evander is offline Competent Performer
    Windows 7 Access 2003
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    206
    Hello. I've had problems with using the literal string \ (backslash) in specifying directories and paths. Using Google, I discovered a solution somewhere. The function Chr() is used instead of the backslash. I'll paste the URL here as soon as I find it. Good luck.

  8. #8
    cg1465 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    8
    Thanks Adam for your help...FYI...here's what actually worked, but opens in readonly. I'm not sure how to set this to normal?

    Dim oApp As Object
    Set oApp = CreateObject("Word.Application")
    oApp.Visible = True
    AppActivate oApp
    oApp.Documents.Open FileName:=FilLoc & "C:\FirstUSA\Prospects\" & Forms![FirstUSA]![Phone1] & ".doc", readonly:=readonly

    Set oApp = Nothing

  9. #9
    cg1465 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    8
    Nevermind...fixed! Just removed the , readonly:=readonly expression. Thanks Adam...much appreciated!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 09-10-2010, 08:00 AM
  2. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  3. Command Button
    By lannoe in forum Forms
    Replies: 1
    Last Post: 07-01-2010, 01:48 PM
  4. Command Button Help!
    By arthura in forum Programming
    Replies: 3
    Last Post: 06-30-2009, 12:55 PM
  5. Create a command button to Browes for file
    By sawill in forum Programming
    Replies: 3
    Last Post: 03-15-2009, 05:02 PM

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