473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Debugging Error Invalid use of Me Keword

2
I am trying to get my form to autofill the values from the last record to the new record. In the form properites on the BeforeInsert, I used the following module

I have been away from VB for several years and am finding it challenging to understand. Can you all help? The other part of the code debugs. See below

I keep getting the same error when I debug this
Compile Error: Invalid use of Me Keyword
Here is the code. What comes back highlighted is the 3rd line, the word Me

Module7
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Form_BeforeInsert(Cancel As Integer)
  4.   Dim strMsg As String
  5.   Call CarryOver(Me, strMsg)
  6.   If strMsg <> vbNullString Then
  7.     MsgBox strMsg, vbInformation
  8.   End If
  9.  
  10. End Sub
Module9
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Public Function CarryOver(frm As Form, strErrMsg As String, ParamArray avarExceptionList()) As Long
  4. On Error GoTo Err_Handler
  5.     'Purpose: Carry over the same fields to a new record, based on the last record in the form.
  6.     'Arguments: frm               = the form to copy the values on.
  7.     '           strErrMsg         = string to append error messages to.
  8.     '           avarExceptionList = list of control names NOT to copy values over to.
  9.     'Return:    Count of controls that had a value assigned.
  10.     'Usage:     In a form's BeforeInsert event, excluding Surname and City controls:
  11.     '               Call CarryOver(Me, strMsg, "Surname", City")
  12.     Dim rs As DAO.Recordset         'Clone of form.
  13.     Dim ctl As Control              'Each control on form.
  14.     Dim strForm As String           'Name of form (for error handler.)
  15.     Dim strControl As String        'Each control in the loop
  16.     Dim strActiveControl As String  'Name of the active control. Don't assign this as user is typing in it.
  17.     Dim strControlSource As String  'ControlSource property.
  18.     Dim lngI As Long                'Loop counter.
  19.     Dim lngLBound As Long           'Lower bound of exception list array.
  20.     Dim lngUBound As Long           'Upper bound of exception list array.
  21.     Dim bCancel As Boolean          'Flag to cancel this operation.
  22.     Dim bSkip As Boolean            'Flag to skip one control.
  23.     Dim lngKt As Long               'Count of controls assigned.
  24.  
  25.     'Initialize.
  26.     strForm = frm.Name
  27.     strActiveControl = frm.ActiveControl.Name
  28.     lngLBound = LBound(avarExceptionList)
  29.     lngUBound = UBound(avarExceptionList)
  30.  
  31.     'Must not assign values to the form's controls if it is not at a new record.
  32.     If Not frm.NewRecord Then
  33.         bCancel = True
  34.         strErrMsg = strErrMsg & "Cannot carry values over. Form '" & strForm & "' is not at a new record." & vbCrLf
  35.     End If
  36.     'Find the record to copy, checking there is one.
  37.     If Not bCancel Then
  38.         Set rs = frm.RecordsetClone
  39.         If rs.RecordCount <= 0& Then
  40.             bCancel = True
  41.             strErrMsg = strErrMsg & "Cannot carry values over. Form '" & strForm & "' has no recrods." & vbCrLf
  42.         End If
  43.     End If
  44.  
  45.     If Not bCancel Then
  46.         'The last record in the form is the one to copy.
  47.         rs.MoveLast
  48.         'Loop the controls.
  49.         For Each ctl In frm.Controls
  50.             bSkip = False
  51.             strControl = ctl.Name
  52.             'Ignore the active control, those without a ControlSource, and those in the exception list.
  53.             If (strControl <> strActiveControl) And HasProperty(ctl, "ControlSource") Then
  54.                 For lngI = lngLBound To lngUBound
  55.                     If avarExceptionList(lngI) = strControl Then
  56.                         bSkip = True
  57.                         Exit For
  58.                     End If
  59.                 Next
  60.                 If Not bSkip Then
  61.                     'Examine what this control is bound to. Ignore unbound, or bound to an expression.
  62.                     strControlSource = ctl.ControlSource
  63.                     If (strControlSource <> vbNullString) And Not (strControlSource Like "=*") Then
  64.                         'Ignore calculated fields (no SourceTable), autonumber fields, and null values.
  65.                         With rs(strControlSource)
  66.                             If (.SourceTable <> vbNullString) And ((.Attributes And dbAutoIncrField) = 0&) _
  67.                                 And Not IsNull(.Value) Then
  68.                                 If ctl.Value = .Value Then
  69.                                     'do nothing. (Skipping this can cause Error 3331.)
  70.                                 Else
  71.                                     ctl.Value = .Value
  72.                                     lngKt = lngKt + 1&
  73.                                 End If
  74.                             End If
  75.                         End With
  76.                     End If
  77.                 End If
  78.             End If
  79.         Next
  80.     End If
  81.  
  82.     CarryOver = lngKt
  83.  
  84. Exit_Handler:
  85.     Set rs = Nothing
  86.     Exit Function
  87.  
  88. Err_Handler:
  89.     strErrMsg = strErrMsg & Err.Description & vbCrLf
  90.     Resume Exit_Handler
  91. End Function
  92.  
  93. Public Function HasProperty(obj As Object, strPropName As String) As Boolean
  94.     'Purpose: Return true if the object has the property.
  95.     Dim varDummy As Variant
  96.  
  97.     On Error Resume Next
  98.     varDummy = obj.Properties(strPropName)
  99.     HasProperty = (Err.Number = 0)
  100. End Function
Apr 30 '10 #1
5 5713
ADezii
8,834 Expert 8TB
  1. In the future, kindly use Code Tags for readability purposes.
  2. I just browsed at your code for a minute, but the syntax for passing the Current Form appears to be OK.
  3. Try two things before we proceed any further:
    • Pass the Absolute Reference to the Form as the Function Argument, namely:
      Expand|Select|Wrap|Line Numbers
      1. Call Carry_Over(Forms("<Form Name>"), strMsg)
    • Explicitly Declare the Parameter in the Function Declaration as Access.Form, namely:
      Expand|Select|Wrap|Line Numbers
      1. Public Function CarryOver(frm As Access.Form, strErrMsg As String, ParamArray avarExceptionList()) As Long
    • I do not see the ParamArray() Values being passed to the Function.
  4. Let us know how you make out.
Apr 30 '10 #2
Abest
2
Thank you for your help. Again I am just getting back to Access and am finding the terms confusing. When I add code above and run, it still stops at Me This seems to be a sticking point I can't get around.
May 1 '10 #3
ADezii
8,834 Expert 8TB
@Abest
Expand|Select|Wrap|Line Numbers
  1. Call CarryOver(Me, strMsg)
  1. What is the Value of strMsg being passed?
  2. Where are the ParamArray() Values being passed?
May 2 '10 #4
NeoPa
32,556 Expert Mod 16PB
I would guess your problem is that module7 is not a form module. The Me keyword, referring as it does to the associated form - IE the form the module is a part of, is only available in form modules. Standard modules could not sensibly have any meaning for Me, so they cannot use it.

Welcome to Bytes!
May 2 '10 #5
robjens
37
Is Paramarray a optional argument? I don't see that statement anywhere. Either way, nothing wrong with passing reference of any object from a form class to a function in a code module as long as your scopes are correct which seems to be the case.
May 2 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Frank Jones | last post by:
When manually running resgen.exe from the command prompt (Visual Studio .NET 2003 command prompt) I get the following error: error: Invalid ResX input. error: Specific exception:...
7
by: bazley | last post by:
I've been tearing my hair out over this: #ifndef MATRIX2_H #define MATRIX2_H #include <QVector> template<class T> class Matrix2 { public:
0
by: Ravikanth[MVP] | last post by:
Hi Check out this KB Article. http://support.microsoft.com/default.aspx?scid=kb%3Ben-us% 3B306172 Ravikanth >-----Original Message-----
1
by: Stephen | last post by:
Hi, I found code snippet for running an app (.exe, .bat) from a web app(using Process class). its pretty interesting but along with the other posts (that i cant run a windows app) i found...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
5
by: Eric | last post by:
I run a program which read emails from a text file. There is some thing invalid in one or more text file. When program is busy doing parsing it shows that error and process stop. I dont know which...
7
by: The|Godfather | last post by:
Hi everybody, I read Scotte Meyer's "Effective C++" book twice and I know that he mentioned something specific about constructors and destructors that was related to the following...
3
by: ravisc | last post by:
Hi, I had .Net 2005 framework installed in my system. I had uninstalled the same. Now I have been working with .Net 2003 develpment environment. when I try to debug any .Net 2003 project, it gives...
8
by: mahmoodn | last post by:
Hi, I have a problem with a compiler error "invalid use of incomplete type". Here is the description: in "first.h", I have: class cache_t { public: virtual void printStats( pseq_t *pseq );...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.