473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

link microsoft word title to a value in access

I am having trouble getting my database to do what i want. I have a
form with autonumbers which are going to be the numbers of some
inventory. the inventory has reports in word or other program. The
file name is going to be the number generated by access, but every file
will be saved in the same folder. i was wondering if there was a way
to click on the button and then have the comput search the correct
folder linking the number in access to the file name and have that file
come up on the screen for viewing.

Jun 22 '06 #1
5 1578

enginerd477 wrote:
I am having trouble getting my database to do what i want. I have a
form with autonumbers which are going to be the numbers of some
inventory. the inventory has reports in word or other program. The
file name is going to be the number generated by access, but every file
will be saved in the same folder. i was wondering if there was a way
to click on the button and then have the comput search the correct
folder linking the number in access to the file name and have that file
come up on the screen for viewing.


create a text field in your table. Store either the full path to the
file or the name and then append the full path to the name

CONST cstrDirectory As STring = "C:\WordDocs\"
then you'd store just the filename, if necessary. Making the Word
filename the same as the autonumber is a little dodgy. You're NOT
guaranteed that some numbers won't be skipped. Then you could do
something like formatting a calculated control as a hyperlink.

txtFilePath = cstrDirectory & Me.txtIDNo & ".doc"

If you format as a hyperlink, the file should open fine.

Jun 24 '06 #2
I'm a little confused so i'm just making sure i got this right, i just
started using access like three weeks ago and so im not as literal in
it as many of you.
So i need to save the files as any name. Then i have to make some
code, can i use the same one and just get rid of the text string and
put in yours, to give me the right directory. then i have to find a
way to get the filename stored in the database.
or
i can keep the same numbering and just create a hyperlink instead using
the autonumbers, or am i using that second part of code to open up the
top part or code.
Thanks for the help

Jun 26 '06 #3

enginerd477 wrote:
I am having trouble getting my database to do what i want. I have a
form with autonumbers which are going to be the numbers of some
inventory. the inventory has reports in word or other program. The
file name is going to be the number generated by access, but every file
will be saved in the same folder. i was wondering if there was a way
to click on the button and then have the comput search the correct
folder linking the number in access to the file name and have that file
come up on the screen for viewing.


If you're a newbie, this may be a bit hard to follow, so I'll try to
explain clearly. If the files already exist in the folder and the
records already exist in a table, but you don't have the full path
stored, you could use some code to get all this for you. (I did that
part for you. Hopefully it's what you wanted.)

All the code was cobbled from this NG or taken from The Access Web.

'---put all this code in a new code module.
Option Compare Database

'************** Code Start **************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code courtesy of
'Terry Kreft

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long

Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer

With bi
.hOwner = hWndAccessApp
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With

dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
Else
BrowseFolder = vbNullString
End If
End Function
'*********** Code End *****************

Then in the form that you want to use to launch the cataloging for you,
'********** Code Start ****************
Option Compare Database

Private Sub Command0_Click()
Dim strDirectory As String
Dim blnFileExists As Boolean
Dim rsFiles As DAO.Recordset

'---prompt the user for the folder to catalog.
strDirectory = BrowseFolder("Select a folder to catalog")

'---open the table containing all the FileNumbers
Set rsFiles = DBEngine(0)(0).OpenRecordset("tblFiles", dbOpenTable)

'---loop over all the records, look for the file (Dir), and if it
exists,
'---mark it as found/existing
'---and write the directory.

Do Until rsFiles.EOF
blnFileExists = (Len(Dir(strDirectory & "\" &
rsFiles.Fields("RecordID") & ".txt")) > 0)
With rsFiles
.Edit
!FileExists = blnFileExists
If blnFileExists Then
!FullPath = strDirectory & "\" &
rsFiles.Fields("RecordID") & ".txt"
End If
.Update
End With
rsFiles.MoveNext
Loop

rsFiles.Close
Set rsFiles = Nothing

End Sub

'*************Code End*************************
I was thinking that you might only want to ignore the files you had
already catalogued, but what if someone deletes one... then you'll get
a Null in your FullPath field.

Hope this makes sense. If you have questions, fire away.

Pieter

Jun 27 '06 #4
Thanks for the help, i found my mistake and got it to work.

i have another problem now. i have multiple file types in the folder
and i want all the files with the report name to open a when i click on
the button. i tried using the following code to see if i could get at
least one of the files to open but instead i got an error message
saying that Compile error: Else without If.

heres the code:

Dim filename As String
Dim file As String
Dim output As String

If filename = "\\averill\public$\Engineering\Part_Database\" &
CStr(Me!Report) & ".doc" Then Application.FollowHyperlink filename

ElseIf file = "\\averill\public$\Engineering\Part_Database\" &
CStr(Me!Report) & ".JPG" Then Application.FollowHyperlink file

Else
output = "No File for this Report Exists!"
End If

End Sub

Thanks for the help.

-------------------------------------------
pi********@hotmail.com wrote:
enginerd477 wrote:
I am having trouble getting my database to do what i want. I have a
form with autonumbers which are going to be the numbers of some
inventory. the inventory has reports in word or other program. The
file name is going to be the number generated by access, but every file
will be saved in the same folder. i was wondering if there was a way
to click on the button and then have the comput search the correct
folder linking the number in access to the file name and have that file
come up on the screen for viewing.


If you're a newbie, this may be a bit hard to follow, so I'll try to
explain clearly. If the files already exist in the folder and the
records already exist in a table, but you don't have the full path
stored, you could use some code to get all this for you. (I did that
part for you. Hopefully it's what you wanted.)

All the code was cobbled from this NG or taken from The Access Web.

'---put all this code in a new code module.
Option Compare Database

'************** Code Start **************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code courtesy of
'Terry Kreft

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long

Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer

With bi
.hOwner = hWndAccessApp
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With

dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
Else
BrowseFolder = vbNullString
End If
End Function
'*********** Code End *****************

Then in the form that you want to use to launch the cataloging for you,
'********** Code Start ****************
Option Compare Database

Private Sub Command0_Click()
Dim strDirectory As String
Dim blnFileExists As Boolean
Dim rsFiles As DAO.Recordset

'---prompt the user for the folder to catalog.
strDirectory = BrowseFolder("Select a folder to catalog")

'---open the table containing all the FileNumbers
Set rsFiles = DBEngine(0)(0).OpenRecordset("tblFiles", dbOpenTable)

'---loop over all the records, look for the file (Dir), and if it
exists,
'---mark it as found/existing
'---and write the directory.

Do Until rsFiles.EOF
blnFileExists = (Len(Dir(strDirectory & "\" &
rsFiles.Fields("RecordID") & ".txt")) > 0)
With rsFiles
.Edit
!FileExists = blnFileExists
If blnFileExists Then
!FullPath = strDirectory & "\" &
rsFiles.Fields("RecordID") & ".txt"
End If
.Update
End With
rsFiles.MoveNext
Loop

rsFiles.Close
Set rsFiles = Nothing

End Sub

'*************Code End*************************
I was thinking that you might only want to ignore the files you had
already catalogued, but what if someone deletes one... then you'll get
a Null in your FullPath field.

Hope this makes sense. If you have questions, fire away.

Pieter


Jun 27 '06 #5
"enginerd477" <ke******@corning.com> wrote in
news:11**********************@j72g2000cwa.googlegr oups.com:
Thanks for the help, i found my mistake and got it to work.

i have another problem now. i have multiple file types in the
folder and i want all the files with the report name to open a
when i click on the button. i tried using the following code
to see if i could get at least one of the files to open but
instead i got an error message saying that Compile error: Else
without If.

heres the code:

Dim filename As String
Dim file As String
Dim output As String

If filename = "\\averill\public$\Engineering\Part_Database\" &
CStr(Me!Report) & ".doc" Then Application.FollowHyperlink
filename

ElseIf file = "\\averill\public$\Engineering\Part_Database\" &
CStr(Me!Report) & ".JPG" Then Application.FollowHyperlink file

Else
output = "No File for this Report Exists!"
End If

End Sub

Thanks for the help.


If then
do something
ElseIf then
do something
Else
do something
endif

NOT
If then do something
ElseIf then do something
Else do something
endif

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jun 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: j erickson | last post by:
with the following xsl and xml file, the display of the gif file with the <image/url> tag works. However, the gif file in the <description> tag using the name attribute "src" won't make the correct...
1
by: Andrew V. Romero | last post by:
I have a script that I am working on for an intranet tool and in this script I have a form, which when submitted the onSubmit command calls calculate(). In this calculate function, I have it do...
3
by: TrvlOrm | last post by:
I am having great difficulty in these asp scripts, using VBscript and JavaScript. I have 4 files that all need to be linked together. The first file "Books.html" - needs to search for a Book...
11
by: WindAndWaves | last post by:
Hi Gurus What I would like to do is to setup a little form where people can put in a date (e.g. Day: Month..... Year , where ... is user input) and subsequently, will take them through to an...
7
by: olga | last post by:
Hi, On my site, i want to pass a javascript variable to php. I know that this needs to done in a link or in a post. I want to know if there is a way i can do it with an html link. I should...
4
by: Miguel Dias Moura | last post by:
Hello, I created a datalist in an ASP.Net / VB page. I display the image and price of a few products. When a user clicks an image I want to load the page "detail.aspx?number=id" and send the...
14
by: hgraham | last post by:
Hi, I'm trying to understand how to work the dom, and all I'm trying to do is insert a link right before another link in the html based on it's href value. This isn't a real world example - I'm...
5
by: md9108 | last post by:
I created, using some borrowed code, an asp search page for our intranet. I'm using frontpage 2003. When I publish I get that complation error on different lines at different times. They all seem...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.