buttton on Continuous Form

S

sebastico

Hello

I've searched previously all posted questions in Access (Form Coding,
General Questions, Module Coding and Programming and I am not finding mine).
Also I checked the Dir Function and I always get error. I also posted a
question with no reply.

So here goes...

In Access 2003 I have a Continuous Form showing a query. The form shows the
fields A, B, C, D, E and F from MyTable. The field F shows all records .pdf
in the database. All files .pdf (from records of field F) are already in
C:\AB\A.

What I need is:
A code in a button of my form (FQMA) that If I put the cursor in field F,
the code will find the file in C:\AB\A, copy the file and paste the file on
Desktop.

Thank you very much
 
A

Albert D. Kallal

Lets assume you click a button that is placed beside the text box for field
F

And, it not clear if field F has the full path name and .pdf extension, or
just the pdf name????

And, it not clear when you mean:

c:\ab\

Do you mean the letters "ab" , or do you want the field value for a and b
???

For this code I assume you mean ab as an location ab, and not the field
values.
(however, if you do mean the field values, it a simple matter to modify the
below)

And, lets assume the field F has the pdf file name with the .pdf as part of
the extension.

dim strDeskTop as string
' get path location to desktop
strDeskTop = CreateObject("Shell.Application").Namespace(&H10&).self.Path

FileCopy "c:\ab\" & Me.f, strDeskTop & "\" & Me.f

Of course, if ab is supposed to be field a + b, then above becomes:

FileCopy "c:\" & me.a & me.b & "\" & Me.f, strDeskTop & "\" & Me.f

And, as mentioned, it not clear if the file extension ".pdf" is included in
field f or not...
 
S

sebastico

Albert
The letters AB and A are file location names.
Yes .pdf is included in the field

I´ll try your code and I let you know. If you thing I have to chance
something please let me know.

Thank you very much indeed
 
S

sebastico

Albert
Following your this is my code:
Private Sub txtf_Click()
Dim strDeskTop As String
'get path location to desktop
strDeskTop = CreateObject("Shell.Application").Namespace(&H10&).self.Path
FileCopy "c:\AB\A\" & Me.f, strDeskTop & "\" & Me.f
End Sub

However, when I click the button VBA shows this message:
Run Time Error 76 Path not found.
In my case I copied the Path fromExplorer.

I don't know how to fix this? Your help is greatly appreciated
 
S

sebastico

Hello

I already fixed the path problem.Now after clicking the button vba displays
this message: Object doesn't support this property or method.I am new to VB
programming. What does this error mean? I have searched the
help file and have not be able to find the answer.

I also replaced the AB, B and f with my actual ones.
This is the code
Private Sub txtPath_Click()
Dim strDeskTop As String
'get path location to desktop
strDeskTop = CreateObject("Shell.Application").Namespace(&H10&).self.Path
FileCopy "c:\BZ\Docs\" & Me.txtPath, strDeskTop & "\" & Me.txtPath
End Sub

Many thanks in advance
 
A

Albert D. Kallal

Create a test form with a simple button on it.

Check if the code that gets the path to the desktop works.

eg:

dim strDeskTop as string

strDeskTop = CreateObject("Shell.Application").Namespace(&H10&).self.Path

msgbox strDeskTop


If the above fails, then that points to our problem we must fix. This might
be an OS issue. I not at an Vista or win7 computer right now, and I find the
above does work on windows xp. So, access version + OS version might be an
issue to look at here....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top