Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 18th, 2009, 11:26 PM
Registered User
 
Join Date: Jan 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compile Error - Method not found

I have an MS Access Database application built and am trying to add in another report. Most of the applictaion I have built is done using macros, queries, forms and a few reports...I have done some actual programming to calculate fields, etc.

However, the report I am building now keeps giving me this error of "method or data member not found". I have confirmed the database field name is correct, the query for the report is correct, I am trying to place the code below in the "onload" event of the report properties.

Dim varNavyUniqueDays As Integer
Dim varITRODays As Integer
Dim varPercentITRO As Integer
Dim x As String
varNavyUniqueDays = 0
varITRODays = 0
varPercentITRO = 0
'Check to see if ITRO Source is Navy. If so add to varNavyUniqueDays. Else add to varITRODays.
If Me.ITRO_AF = True Then
x = MsgBox("hello")
End If

The error occurs at "Me.ITRO_AF = True Then"

I have used this code to manipulate data on another "form" and it worked fine....but here it does not. I am confused. Your help is greatly appreciated.
Dave
 
Old January 19th, 2009, 03:36 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Are you *sure* that your ME is the right object at the point in the code you are at???

That is, what object has that ITRO_AF member? And *is* it the SAME object that this code is a method or event handler for??

Consider: If you know that the object that has ITRO_AF for a member *also* has (say) a NAME member, you could try doing
MsgBox(Me.Name)

Or maybe you could do
MsgBox(TypeName(Me))

I'm not sure VBA supports TYPENAME (it's present in VBScript), but if it does, then it will nicely tell you exactly what data type the object is that ME is referring to.
 
Old January 19th, 2009, 01:45 PM
Registered User
 
Join Date: Jan 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply.
When I type "ME." the Quick Info box pops up and I selected the "ITRO_AF" field from the drop down list....so if I understand correctly, the object and member are correct.

The line: x = MsgBox("hello") is there as a trouble shooting point, so I can work my way through the code as I build it. The code (as I am sure you know) will not process past the line: If Me.ITRO_AF = True Then
Which I do not understand, as this is the exact same code (I copied it) from another procedure associated with a form I have built. The form works fine.

Here is the code I copied from (it is in BOLD):

Private Sub Form_Current()
'Set initial conditions for ITRO, HOST, CoLocation Labels
Label309.Visible = False
Label311.Visible = False
Label313.Visible = False
Label314.Visible = False
Label352.Visible = False
Label353.Visible = False
Label358.Visible = False
Label359.Visible = False

'Check and report if Course is ITRO
If Me.ITRO_Army = True Then
Label309.Visible = True 'On CRS Tab
Label352.Visible = True 'On CRS Review Tab
ElseIf Me.ITRO_AF = True Then
Label309.Visible = True 'On CRS Tab
Label352.Visible = True 'On CRS Review Tab
ElseIf Me.ITRO_CG = True Then
Label309.Visible = True 'On CRS Tab
Label352.Visible = True 'On CRS Review Tab
ElseIf Me.ITRO_Navy = True Then
Label309.Visible = True 'On CRS Tab
Label352.Visible = True 'On CRS Review Tab
ElseIf Me.ITRO_USMC = True Then
Label309.Visible = True 'On CRS Tab
Label352.Visible = True 'On CRS Review Tab
Else
Label311.Visible = True 'On CRS Tab
Label353.Visible = True 'On CRS Review Tab
End If



Thanks again for your help.
Dave
 
Old January 19th, 2009, 06:05 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Weird. Why would that one not work and all the others work. Kind of out of ideas.

I'd still try doing
MsgBox( TypeName(Me) )
at that point, just to see what it says. (Yes, just for debugging.) But I strongly suspect it's not going to tell you anything useful, unfortunately.
 
Old January 19th, 2009, 07:23 PM
Registered User
 
Join Date: Jan 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried that....the compile process stops at: If Me.ITRO_AF=True Then

And it hi-lights in blue: ITRO_AF

And the error msg dialog box states:

Compile error
Method or data member not found. OK Help.

When I click "OK", the procedure name is hi-lighted in yellow and there is a yellow arrow pointing to the procedure name: Private Sub Report_Load()


So - I tried the following code:

' If Me.ITRO_AF = True Then
' x = MsgBox("hello")
x = MsgBox(TypeName(Me))

and the msgbox displayed:

Report_Rpr-CSFE-A-School-Trng-Data

which is the correct report.



Is it related to the previous code I copied was from a "form" and I am trying to use this code in a "report"?

If this way does not work, can you suggest another way I can check the value of a text field in the database, and based on that value, do an action....like the "If then else" process.

Thanks again.
Dave
 
Old January 19th, 2009, 09:05 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I'm afraid I just don't have any suggestions. It's a lame thing to try, but you *MIGHT* try simply renaming from ITRO_AF to some temp dummy name. Just in case the VBA compiler is utilizing a hashing algorithm on member names and you coincidentally have two members with the same hash value. But I don't really think that's the case.

The fact that intellisense showed that this *is* a member is especially confusing/exasperating. Yeah, the "report" needs to have that field as a member, but if you copied *all* the members, it should be there. And, again, intellisense says it's there.

I'm afraid you've exhausted my ideas. Wish I could tell you otherwise. Sorry.
 
Old January 19th, 2009, 10:51 PM
Registered User
 
Join Date: Jan 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help.

I will keep trying.....
Dave
 
Old January 19th, 2009, 11:03 PM
Registered User
 
Join Date: Jan 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok...you mentioned if it was on the report......which got me to thinking.....

I have the code written in the procedure, but I never actually placed the field on/in the report. When I place the data field in the report, the code logic works with no problem. So I learned something there....Thanks.

Now my question is - how do I run this logic code to check on the contents of a data field without placing the data field on / in the report?
 
Old January 20th, 2009, 03:10 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I am *not* Access VBA person. Barely dabbled in it. But...

How about making a reference to the form from the report??? Then you could use
Me.referenceToForm.memberOfForm
????

That is, if you named your form reference something useful, such as "TheForm" then you could do
Me.TheForm.ITRO_AF

Now, how you assign a reference to the form to that variable???





Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile error - method or data member not found ultimo01 Access VBA 4 January 14th, 2009 09:43 AM
Compile Error data member not found alfiee Access VBA 1 July 7th, 2006 05:35 PM
Server Error in '/' Application - Method not found Jan_Ma Classic ASP Professional 0 October 16th, 2003 08:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.