Open Workbook

  • Thread starter Thread starter auujxa2 via AccessMonster.com
  • Start date Start date
A

auujxa2 via AccessMonster.com

I have a query that pulls 2 fields from a table. One field (ReportName) is
selected from a form combo box. The second field (ReportLocation) in the
query is the full path of the ReportName selected. I want to open the
workbook using the ReportLocation, when the ReportName in the form changes.

So I need to the code to enter in "On Change" for my form, so whatever report
is selected, it opens up.

Please help. Thank you in advance.
 
here is my current code that doesn't work:

Application.FollowHyperlink ([Queries]![qry-ReportList]![ReportLocation])
 
auujxa2 said:
here is my current code that doesn't work:

Application.FollowHyperlink ([Queries]![qry-ReportList]![ReportLocation])
I have a query that pulls 2 fields from a table. One field (ReportName) is
selected from a form combo box. The second field (ReportLocation) in the
query is the full path of the ReportName selected. I want to open the
workbook using the ReportLocation, when the ReportName in the form changes.

So I need to the code to enter in "On Change" for my form, so whatever report
is selected, it opens up.

Please help. Thank you in advance.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

1. You shouldn't use the "On Change" event, 'cuz it fires every time
you press a key. Use the "After Update" event instead - it fires when
the user selects an item from the ComboBox's drop-down list.

2. You can't retrieve the result of a query using the method you show
in your post. You have to create a Recordset and then read the column
value from the recordset.

Ex:

Private Sub cboReportName_AfterUpdate()

Const QRY = "qry-ReportList"

' I like DAO. Remember to check DAO in Tools > References
Dim db As DAO.Database, qd As DAO.QueryDef, rs AS DAO.Recordset
Dim strReportLocation As String

' Check that user selected a report
If Not IsNull(Me!cboReportName) Then

' Set up Recordset
Set db = CurrentDB
Set qd = db.QueryDefs(QRY)
Set rs = qd.OpenRecordset()

' Did we get anything?
If Not rs.EOF Then
strReportLocation = Nz(rs!ReportLocation,"")

' Now open the workbook if there is a location
If Len(strReportLocation)>0 Then
FollowHyperlink strReportLocation
Else
' tell user no report
MsgBox "Report is not stored on system"
End If
Else
' Tell user nothing found
MsgBox "No Record Found"
End If


End If

' clean up - You should have ERROR HANDLERS here
On Error Resume Next
set rs = nothing
set qd = nothing
set db = nothing

End Sub

hth,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBR7bHnIechKqOuFEgEQJYKQCg4r+LK/kJHubr6CFlMP7YVkbRkcwAoNSR
gdeQc7XyjV4aBA/BUmRLwOBN
=By9G
-----END PGP SIGNATURE-----
 
Back
Top