opening a pdf from criteria entered by user

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

User will enter a number for a contract in a text box. The contract number
is the primary key. After the user enters the number, if the number exists
in the table I wanted to be able to search a folder on our network to see if
that .pdf exits...if so I want to open the pdf for that contract number.
Will I need code to do that? What may that look like?

Note...the folder and contract number will never change.
 
Kate,

Private Sub txtContractNo_AfterUpdate()
Dim sFileName As String

sFileName = "c:\somedirectory\" & Me!txtContractNo & ".pdf"

' Check that something exists in the textbox
If Len(Me!txtContractNo) > 0 Then
' Check if the record exists in the table
If DLookup("[ContractNo]", "tblContractsTable", "[ContractID] = " &
Me!txtContractNo Then
' Check if the file exists
If Len(Dir(sFileName, 1)) > 0 Then
' Open the file
ExecuteFile sFileName, "Open"
Else
DoCmd.Beep
MsgBox "File not found"
End If
Else
DoCmd.Beep
MsgBox "The file doesn't have a matching record"
End If
End If
End Sub

For the ExecuteFile() function, see
http://www.pacificdb.com.au/MVP/Code/ExeFile.htm

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Graham, thanks for all the help. You'll have to excuse me I have limited
programming knowledge. Where do I declare the function for the
ExecuteFile()? And if I plug in that function and the code for it...then
plug the code below for the text box..this should all just flow? Actually I
wanted to add a button that the user pushes when finished inputing the
filename...I would put the code below for the button. I'm sorry if I sound
confusing...I'm a bit confused myself. Thanks.

Graham R Seach said:
Kate,

Private Sub txtContractNo_AfterUpdate()
Dim sFileName As String

sFileName = "c:\somedirectory\" & Me!txtContractNo & ".pdf"

' Check that something exists in the textbox
If Len(Me!txtContractNo) > 0 Then
' Check if the record exists in the table
If DLookup("[ContractNo]", "tblContractsTable", "[ContractID] = " &
Me!txtContractNo Then
' Check if the file exists
If Len(Dir(sFileName, 1)) > 0 Then
' Open the file
ExecuteFile sFileName, "Open"
Else
DoCmd.Beep
MsgBox "File not found"
End If
Else
DoCmd.Beep
MsgBox "The file doesn't have a matching record"
End If
End If
End Sub

For the ExecuteFile() function, see
http://www.pacificdb.com.au/MVP/Code/ExeFile.htm

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Kate said:
User will enter a number for a contract in a text box. The contract
number
is the primary key. After the user enters the number, if the number
exists
in the table I wanted to be able to search a folder on our network to see
if
that .pdf exits...if so I want to open the pdf for that contract number.
Will I need code to do that? What may that look like?

Note...the folder and contract number will never change.
 
Kate,

Put FileExecute() in a standard module.

<<if I plug in that function and the code for it...then plug the code below
for the text box..this should all just flow?>>
Yes, but if you want the user to press a button, then transfer the code for
txtContractNo_AfterUpdate() to cmdMyButton_Click().

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Kate said:
Graham, thanks for all the help. You'll have to excuse me I have limited
programming knowledge. Where do I declare the function for the
ExecuteFile()? And if I plug in that function and the code for it...then
plug the code below for the text box..this should all just flow? Actually
I
wanted to add a button that the user pushes when finished inputing the
filename...I would put the code below for the button. I'm sorry if I
sound
confusing...I'm a bit confused myself. Thanks.

Graham R Seach said:
Kate,

Private Sub txtContractNo_AfterUpdate()
Dim sFileName As String

sFileName = "c:\somedirectory\" & Me!txtContractNo & ".pdf"

' Check that something exists in the textbox
If Len(Me!txtContractNo) > 0 Then
' Check if the record exists in the table
If DLookup("[ContractNo]", "tblContractsTable", "[ContractID] = "
&
Me!txtContractNo Then
' Check if the file exists
If Len(Dir(sFileName, 1)) > 0 Then
' Open the file
ExecuteFile sFileName, "Open"
Else
DoCmd.Beep
MsgBox "File not found"
End If
Else
DoCmd.Beep
MsgBox "The file doesn't have a matching record"
End If
End If
End Sub

For the ExecuteFile() function, see
http://www.pacificdb.com.au/MVP/Code/ExeFile.htm

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Kate said:
User will enter a number for a contract in a text box. The contract
number
is the primary key. After the user enters the number, if the number
exists
in the table I wanted to be able to search a folder on our network to
see
if
that .pdf exits...if so I want to open the pdf for that contract
number.
Will I need code to do that? What may that look like?

Note...the folder and contract number will never change.
 
Graham. I'm just getting back to this now. I put FileExecute in its own
standard module. Where do I put all of the fixed length Public Const. I've
tried everywhere but get compiler errors. Do they belong somewhere else in
the project?

Graham R Seach said:
Kate,

Put FileExecute() in a standard module.

<<if I plug in that function and the code for it...then plug the code below
for the text box..this should all just flow?>>
Yes, but if you want the user to press a button, then transfer the code for
txtContractNo_AfterUpdate() to cmdMyButton_Click().

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Kate said:
Graham, thanks for all the help. You'll have to excuse me I have limited
programming knowledge. Where do I declare the function for the
ExecuteFile()? And if I plug in that function and the code for it...then
plug the code below for the text box..this should all just flow? Actually
I
wanted to add a button that the user pushes when finished inputing the
filename...I would put the code below for the button. I'm sorry if I
sound
confusing...I'm a bit confused myself. Thanks.

Graham R Seach said:
Kate,

Private Sub txtContractNo_AfterUpdate()
Dim sFileName As String

sFileName = "c:\somedirectory\" & Me!txtContractNo & ".pdf"

' Check that something exists in the textbox
If Len(Me!txtContractNo) > 0 Then
' Check if the record exists in the table
If DLookup("[ContractNo]", "tblContractsTable", "[ContractID] = "
&
Me!txtContractNo Then
' Check if the file exists
If Len(Dir(sFileName, 1)) > 0 Then
' Open the file
ExecuteFile sFileName, "Open"
Else
DoCmd.Beep
MsgBox "File not found"
End If
Else
DoCmd.Beep
MsgBox "The file doesn't have a matching record"
End If
End If
End Sub

For the ExecuteFile() function, see
http://www.pacificdb.com.au/MVP/Code/ExeFile.htm

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

User will enter a number for a contract in a text box. The contract
number
is the primary key. After the user enters the number, if the number
exists
in the table I wanted to be able to search a folder on our network to
see
if
that .pdf exits...if so I want to open the pdf for that contract
number.
Will I need code to do that? What may that look like?

Note...the folder and contract number will never change.
 
Kate,

I repeat, "Put ExecuteFile() in a standard module.". That means put *all*
the code (including the constants) you find on that web page, into the same
module.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Kate said:
Graham. I'm just getting back to this now. I put FileExecute in its own
standard module. Where do I put all of the fixed length Public Const.
I've
tried everywhere but get compiler errors. Do they belong somewhere else
in
the project?

Graham R Seach said:
Kate,

Put FileExecute() in a standard module.

<<if I plug in that function and the code for it...then plug the code
below
for the text box..this should all just flow?>>
Yes, but if you want the user to press a button, then transfer the code
for
txtContractNo_AfterUpdate() to cmdMyButton_Click().

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Kate said:
Graham, thanks for all the help. You'll have to excuse me I have
limited
programming knowledge. Where do I declare the function for the
ExecuteFile()? And if I plug in that function and the code for
it...then
plug the code below for the text box..this should all just flow?
Actually
I
wanted to add a button that the user pushes when finished inputing the
filename...I would put the code below for the button. I'm sorry if I
sound
confusing...I'm a bit confused myself. Thanks.

:

Kate,

Private Sub txtContractNo_AfterUpdate()
Dim sFileName As String

sFileName = "c:\somedirectory\" & Me!txtContractNo & ".pdf"

' Check that something exists in the textbox
If Len(Me!txtContractNo) > 0 Then
' Check if the record exists in the table
If DLookup("[ContractNo]", "tblContractsTable", "[ContractID]
= "
&
Me!txtContractNo Then
' Check if the file exists
If Len(Dir(sFileName, 1)) > 0 Then
' Open the file
ExecuteFile sFileName, "Open"
Else
DoCmd.Beep
MsgBox "File not found"
End If
Else
DoCmd.Beep
MsgBox "The file doesn't have a matching record"
End If
End If
End Sub

For the ExecuteFile() function, see
http://www.pacificdb.com.au/MVP/Code/ExeFile.htm

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

User will enter a number for a contract in a text box. The contract
number
is the primary key. After the user enters the number, if the number
exists
in the table I wanted to be able to search a folder on our network
to
see
if
that .pdf exits...if so I want to open the pdf for that contract
number.
Will I need code to do that? What may that look like?

Note...the folder and contract number will never change.
 
Back
Top