Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA in Access Help

Status
Not open for further replies.

mikskibum

MIS
Jul 10, 2003
3
US
I am having trouble with the following function. I am trying alert users to close the spreadsheet, if it is open, before executing a command. The function is just bypassing the whole part about whether the spreadsheet is open or not. Any help would be greatly appreciated.


Private Function WorkbookIsOpen(wbname) As Boolean
' Returns TRUE if the workbook is open
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then WorkbookIsOpen = True _
Else WorkbookIsOpen = False
End Function


Private Sub cmdNewBusCon_Click()
Dim stDocName As String

If WorkbookIsOpen("test.xls") = True Then
MsgBox ("Please save your spreadsheets and close them")
Else:
DoCmd.OutputTo acOutputTable, "OneClickNewNotifsForBoth", "Microsoft Excel (*.xls)", "C:\test.xls", True
Exit Sub
End If
Exit_cmdNewBusCon_Click:
Exit Sub

End Sub
 
Presumably the Function WorkbookIsOpen(wbname) is not on the spreadsheet being tested by the Sub cmdNewBusCon_Click(). This being the case, I would not expect the Function WorkbookIsOpen(wbname) to be private
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top