?
Solved

Compile Error: Sub or Function not defined

Posted on 2012-08-28
19
Medium Priority
?
2,028 Views
Last Modified: 2012-08-30
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?
0
Comment
Question by:lauriecking0623
  • 6
  • 5
  • 3
  • +2
19 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38343080
<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.
0
 

Author Comment

by:lauriecking0623
ID: 38343091
@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.
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 38343098
use acb_apiIsIconic in your code...
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 

Author Comment

by:lauriecking0623
ID: 38343130
@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
0
 
LVL 75
ID: 38343131
PtrSafe >>  http://msdn.microsoft.com/en-us/library/office/gg278832.aspx
Are you on a Win 7 X64 system?

mx
0
 
LVL 58
ID: 38343133
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.
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 38343169
so we solved the original issue by calling the proper function name... now we have different issue... make that function public as well...
0
 

Author Comment

by:lauriecking0623
ID: 38343170
@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
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 38343173
what is the exact message now (regarding acbCheckMail)?
0
 
LVL 75
ID: 38343180
0
 
LVL 75
ID: 38343191
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
0
 
LVL 58
ID: 38343203
<<@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.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38343224
< I'll unmonitor this question, looks like you're in good hands here >
0
 
LVL 75
ID: 38343261
" 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
0
 
LVL 58
ID: 38343346
@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.
0
 

Author Comment

by:lauriecking0623
ID: 38351173
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
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 38351205
Seems you need this:



If Not rstClone.EOF Then
   rstClone.MoveFirst
   frmMail.Caption = "New Mail!"
   If  acb_apiIsIconic (frmMail.Hwnd) Then
        frmMail.SetFocus
         DoCmd.Restore
    End If
0
 

Author Closing Comment

by:lauriecking0623
ID: 38351256
This worked in my database. I am extremely happy.
0
 
LVL 75
ID: 38351270
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question