lauriecking0623
asked on
Compile Error: Sub or Function not defined
Ok, now the error that I am getting is
Compile Error: Sub or Function not defined and the following is highlighted in the vba code as follows:
If Not rstClone.EOF Then
rstClone.MoveFirst
frmMail.Caption = "New Mail!"
If IsIconic (frmMail.Hwnd) Then
frmMail.SetFocus
DoCmd.Restore
End If
IsIconic is highlighted by the debugger. I do not know why. I have declared my function as follows
Declare PtrSafe Function acb_apiIsIconic Lib "user32" _
Alias "IsIconic" (ByVal Hwnd As Long) As Long
Does anyone have any suggestions?
Compile Error: Sub or Function not defined and the following is highlighted in the vba code as follows:
If Not rstClone.EOF Then
rstClone.MoveFirst
frmMail.Caption = "New Mail!"
If IsIconic (frmMail.Hwnd) Then
frmMail.SetFocus
DoCmd.Restore
End If
IsIconic is highlighted by the debugger. I do not know why. I have declared my function as follows
Declare PtrSafe Function acb_apiIsIconic Lib "user32" _
Alias "IsIconic" (ByVal Hwnd As Long) As Long
Does anyone have any suggestions?
<wild guess>
Make sure your API call is in the top of a module, above the line that is the divider between the global declaration section and functions/subs
What's the purpose of the PrtSafe? Haven't seen that before.
ASKER
@jimhorn,
(1) I have declared the function in the area that you mentioned.
(2) I have to put PtrSafe because I have Access 2010 64-bit. The function won't work for it without it.
(1) I have declared the function in the area that you mentioned.
(2) I have to put PtrSafe because I have Access 2010 64-bit. The function won't work for it without it.
use acb_apiIsIconic in your code...
ASKER
@HainKurt,
I have made that change, I am still having the same issues. Now, it is highlighting
Function acbCheckMail() As Integer
Here is the whole code:
Function acbCheckMail() As Integer
'Check for new mail, and if there is any,
'restore the received mail form
On Error GoTo HandleErr
Dim rstClone As DAO.Recordset
Dim frmMail As Form
Set rstClone = frmMail.RecordsetClone
If Not rstClone.EOF Then
rstClone.MoveFirst
frmMail.Caption = "New Mail!"
If IsIconic (frmMail.Hwnd) Then
frmMail.SetFocus
DoCmd.Restore
End If
Else
frmMail.Caption = "No Mail"
End If
ExitHere:
Exit Function
HandleErr:
Select Case Err.Number
Case 3021 'no current record do nothing
Case Else
MsgBox Err & ": " & Err.Description, , "acbCheckMail ()"
End Select
Resume ExitHere
End Function
I have made that change, I am still having the same issues. Now, it is highlighting
Function acbCheckMail() As Integer
Here is the whole code:
Function acbCheckMail() As Integer
'Check for new mail, and if there is any,
'restore the received mail form
On Error GoTo HandleErr
Dim rstClone As DAO.Recordset
Dim frmMail As Form
Set rstClone = frmMail.RecordsetClone
If Not rstClone.EOF Then
rstClone.MoveFirst
frmMail.Caption = "New Mail!"
If IsIconic (frmMail.Hwnd) Then
frmMail.SetFocus
DoCmd.Restore
End If
Else
frmMail.Caption = "No Mail"
End If
ExitHere:
Exit Function
HandleErr:
Select Case Err.Number
Case 3021 'no current record do nothing
Case Else
MsgBox Err & ": " & Err.Description, , "acbCheckMail ()"
End Select
Resume ExitHere
End Function
PtrSafe >> http://msdn.microsoft.com/en-us/library/office/gg278832.aspx
Are you on a Win 7 X64 system?
mx
Are you on a Win 7 X64 system?
mx
IsIconic() should work...make sure you have the declare in the proper place as Jim H said and that it's in a standard module.
Jim.
Jim.
so we solved the original issue by calling the proper function name... now we have different issue... make that function public as well...
ASKER
@Database MX: Yes, we are running Windows 7 64-bit
@JDettman: I have it declared in the proper place.
Option Compare Database
Option Explicit
Declare PtrSafe Function acb_apiIsIconic Lib "user32" Alias _
"IsIconic" (ByVal Hwnd As Long) As Long
__________________________ __________ __________ __________ __________ __________ _______-
The rest of my code
@JDettman: I have it declared in the proper place.
Option Compare Database
Option Explicit
Declare PtrSafe Function acb_apiIsIconic Lib "user32" Alias _
"IsIconic" (ByVal Hwnd As Long) As Long
__________________________
The rest of my code
what is the exact message now (regarding acbCheckMail)?
I wonder if you need this, which does actually compile:
#If Vba7 Then
Declare PtrSafe Function acb_apiIsIconic Lib "user32" Alias "IsIconic" (ByVal Hwnd As Long) As Long
#Else
Declare Function acb_apiIsIconic Lib "user32." Alias "IsIconic" (ByVal Hwnd As Long) As Long
#End If
mx
#If Vba7 Then
Declare PtrSafe Function acb_apiIsIconic Lib "user32" Alias "IsIconic" (ByVal Hwnd As Long) As Long
#Else
Declare Function acb_apiIsIconic Lib "user32." Alias "IsIconic" (ByVal Hwnd As Long) As Long
#End If
mx
<<@JDettman: I have it declared in the proper place. >>
Put it all on one line; you have it aliased properly and IsIconic() should work.
Declare PtrSafe Function acb_apiIsIconic Lib "user32" Alias "IsIconic" (ByVal Hwnd As Long) As Long
@MX,
<<I wonder if you need this, which does actually compile:>>
You only need to use compiler directives if your developing a DB both for 32 and 64 bit Office versions.
Jim.
Put it all on one line; you have it aliased properly and IsIconic() should work.
Declare PtrSafe Function acb_apiIsIconic Lib "user32" Alias "IsIconic" (ByVal Hwnd As Long) As Long
@MX,
<<I wonder if you need this, which does actually compile:>>
You only need to use compiler directives if your developing a DB both for 32 and 64 bit Office versions.
Jim.
< I'll unmonitor this question, looks like you're in good hands here >
" You only need to use compiler directives if your developing a DB both for 32 and 64 bit Office versions."
Understood. But I wonder if that is the case here ?
mx
Understood. But I wonder if that is the case here ?
mx
@mx,
<<Understood. But I wonder if that is the case here ?>>
Possibly. Certainly won't hurt. But she said she was running under 64 bit with this issue, so it's just extra code for the moment. Something else is going on.
Jim.
<<Understood. But I wonder if that is the case here ?>>
Possibly. Certainly won't hurt. But she said she was running under 64 bit with this issue, so it's just extra code for the moment. Something else is going on.
Jim.
ASKER
I am still having issues with the code. Attached is the screenshot for the issues. Anyone that can help, i would truly appreciate it since I got it work except this one part. I am so beyond frustrated.
Issues-with-the-errors.jpg
Issues-with-the-errors.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This worked in my database. I am extremely happy.
You were referencing the API name, not the new name you gave it.
I do what you did ... rename all API calls to a consistent naming convention to fit my needs.
mx
I do what you did ... rename all API calls to a consistent naming convention to fit my needs.
mx