Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 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 March 1st, 2004, 06:47 AM
Authorized User
 
Join Date: Jul 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Invaild use of Me keyword

Hi

I put the following code - taken from a Wrox book - into a module thinking that it would be available to multiple forms. The function simply clears any fields on a form, ready for fresh input.

Public Sub clearFields()
With Me.Controls
  For indx = 0 To .Count - 1
    If Me.Controls(indx).Tag = "1" Then
      If (TypeOf Me.Controls(indx) Is TextBox) Then
        Me.Controls(indx).Text = ""
      ElseIf (TypeOf Me.Controls(indx) Is MaskEdBox) Then
        tempMask = Me.Controls(indx).Mask
        Me.Controls(indx).Mask = ""
        Me.Controls(indx).Text = ""
        Me.Controls(indx).Mask = tempMask
      ElseIf (TypeOf Me.Controls(indx) Is OptionButton) Then
        Me.Controls(indx).Value = False
      Else
        Me.Controls(indx).Caption = ""
      End If
    End If
  Next
End With
End Sub

However, when I try to run the program I get a compile error: Invalid use of Me keyword. I guess I can't use "Me" in a module? Any ideas gratefully received. Thanks.
 
Old March 1st, 2004, 07:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

That's right, you can't use 'Me' in a module. The easiest way around this would be to supply the Form you want to run this code against as an object parameter, then pass it in as 'Me' from the calling form.
i.e. change the function signature to Public Sub clearFields(objForm as Form), then replace all the instances of 'Me' in the function with 'objForm'. Then when you call the function from each form, just use: Call clearFields(Me)

hth
Phil
 
Old March 1st, 2004, 07:23 AM
Authorized User
 
Join Date: Jul 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excellent Phil, thanks!

 
Old September 28th, 2004, 10:53 AM
Authorized User
 
Join Date: Sep 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Lalit_Pratihari
Default

Hi,

Phil is right. We can't use ME keyword in a module.

Lalit
Life Means More...;)





Similar Threads
Thread Thread Starter Forum Replies Last Post
The "New" Keyword rfarmer VB Components 1 August 16th, 2006 12:18 PM
MyBase Keyword Little Shell VB.NET 2002/2003 Basics 2 May 2nd, 2005 05:18 PM
keyword doesn't appear with result gilgalbiblewheel Classic ASP Databases 2 January 11th, 2005 12:45 AM
this keyword RSteel C# 1 December 18th, 2003 04:33 AM





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