Error User defined type not defined

G

gizmositka

I am trying to write code for a save button on a form use VBA. I have the
11.0 Object reference selected and I still get a User-defined type not
defined error.

Here is the code

'Dim dlgSaveAs As FileDialog

'Set dlgSaveAs = Application.FileDialog(msoFileDialogSelcetdItems)
' dlgSaveAs.Show
' Dim result As DialogResult
' Dim fileName As String
'dlgSaveAs.CheckFileExists = False

' If result = DialogResult.Cancel Then
' Return
' End If

' fileName = dlgSaveAs.fileName
' If (fileName = "" Or fileName = Nothing) Then
' MsgBox("Invalid File Name", vbOKCancel) As VbMsgBoxResult
' Else

'Try
'output = New FileStream(fileName, FileMode.OpenOrCreate,
FileAccess.Write)
' cmdSave.Enabled = False
' cmdEnter.Enabled = True

' Catch fileException As FileNotFoundException
'MsgBox("File does not exist!", vbOKOnly) As VbMsgBoxResult

'End Try

The error happens on the first line when I try to declare the dlgSaveAs as a
FileDialog.

Help is greatly appreciated.
 
A

Allen Browne

Try adding a reference to the Microsoft Office 11 Object library.

IME, it's not worth messing with FileDialog. It doesn't work in all
versions, and it doesn't work at all for SaveAs. You would be better off to
take the plunge and copy the API code from this link:
http://www.mvps.org/access/api/api0001.htm
 
G

gizmositka

Thank-you.

Now the only error I am getting is "Sub or function is not defined. I tried
to use the Declare function - but no matter where I put it - I get an error
stating I cannot put it here.

aht_apiGetOpenFileName(OFN)
 

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