Replacing "Me" in a standard module 
Author Message
 Replacing "Me" in a standard module

I am trying to move code from a Sub in a class (Form)
module to a Function in a standard module to be used by
multiple Forms in my database. The function is to Close
an Edit Form (with only 1 record) and Open a View Form
(with many records where edits/deletions/additions are
not allowed) at the same record that was just edited. My
problem is getting the syntax correct for replacing
a "Me" in the Form Code Module with the correct code in
the Standard Code Module. I am using string variables to
define the EditForm, ViewForm, and SyncField. These
variables are defined in a Public Module as Public String
variables for general use.

The statements (with "Me") that work in the EditForm
Module are as follows:
'If the Synch Field is blank, then exit the Sub.
   If IsNull(Me([strSynField])) Then
      Exit Sub
   End If

and

'Define the form object and Recordset object for the View
Form.
   Set frm = Forms(strViewForm)
   Set RS = frm.RecordsetClone

   'Define the criteria used for the synchronization.
   SyncCriteria = BuildCriteria(strSynField, dbText, Me
([strSynField]))

The statements that don't work when I move the code to
the Standard Module are as follows:

   If IsNull(Forms!strEditForm!([strSynField])) Then

and

   SyncCriteria = BuildCriteria(strSynField, dbText,
Forms!strViewForm!([strSynField]))

I would appreciate help in getting the correct syntax.

Thanks, Richard



Mon, 01 Aug 2005 20:34:22 GMT  
 Replacing "Me" in a standard module
Hi,
When using string variables to represent a form name,
use the syntax:

Forms(strVariable)

So:
Forms(strEditForm)!strSynField

--
HTH
Dan Artuso, MVP

"a problem well stated is a problem half solved"


Quote:
> I am trying to move code from a Sub in a class (Form)
> module to a Function in a standard module to be used by
> multiple Forms in my database. The function is to Close
> an Edit Form (with only 1 record) and Open a View Form
> (with many records where edits/deletions/additions are
> not allowed) at the same record that was just edited. My
> problem is getting the syntax correct for replacing
> a "Me" in the Form Code Module with the correct code in
> the Standard Code Module. I am using string variables to
> define the EditForm, ViewForm, and SyncField. These
> variables are defined in a Public Module as Public String
> variables for general use.

> The statements (with "Me") that work in the EditForm
> Module are as follows:
> 'If the Synch Field is blank, then exit the Sub.
>    If IsNull(Me([strSynField])) Then
>       Exit Sub
>    End If

> and

> 'Define the form object and Recordset object for the View
> Form.
>    Set frm = Forms(strViewForm)
>    Set RS = frm.RecordsetClone

>    'Define the criteria used for the synchronization.
>    SyncCriteria = BuildCriteria(strSynField, dbText, Me
> ([strSynField]))

> The statements that don't work when I move the code to
> the Standard Module are as follows:

>    If IsNull(Forms!strEditForm!([strSynField])) Then

> and

>    SyncCriteria = BuildCriteria(strSynField, dbText,
> Forms!strViewForm!([strSynField]))

> I would appreciate help in getting the correct syntax.

> Thanks, Richard



Mon, 01 Aug 2005 20:53:12 GMT  
 Replacing "Me" in a standard module
A fairly simple way to do this is to pass "Me" as a reference to the generic
function. Then just replace "Me" with the name of the variable:

Public Function DoSomething(frm As Form)
    Debug.Print frm.Name
    If frm.Visible Then ...
    frm!SomeControl = 4
    frm("AnotherControl") = "Jones"
End Function

Each form can then call the generic function like this:
    Call DoSomething(Me)
or you could even reference it directly from in the Properties by using
"[Form]":
    =DoSomething([Form])

--
Allen Browne - Microsoft MVP (Most Valuable Professional)
Allen Browne's Database And Training - Perth, Western Australia.
Tips for MS Access users - http://allenbrowne.com/tips.html
Reply to the newsgroup. (Email address has spurious "_SpamTrap")


Quote:
> I am trying to move code from a Sub in a class (Form)
> module to a Function in a standard module to be used by
> multiple Forms in my database. The function is to Close
> an Edit Form (with only 1 record) and Open a View Form
> (with many records where edits/deletions/additions are
> not allowed) at the same record that was just edited. My
> problem is getting the syntax correct for replacing
> a "Me" in the Form Code Module with the correct code in
> the Standard Code Module. I am using string variables to
> define the EditForm, ViewForm, and SyncField. These
> variables are defined in a Public Module as Public String
> variables for general use.

> The statements (with "Me") that work in the EditForm
> Module are as follows:
> 'If the Synch Field is blank, then exit the Sub.
>    If IsNull(Me([strSynField])) Then
>       Exit Sub
>    End If

> and

> 'Define the form object and Recordset object for the View
> Form.
>    Set frm = Forms(strViewForm)
>    Set RS = frm.RecordsetClone

>    'Define the criteria used for the synchronization.
>    SyncCriteria = BuildCriteria(strSynField, dbText, Me
> ([strSynField]))

> The statements that don't work when I move the code to
> the Standard Module are as follows:

>    If IsNull(Forms!strEditForm!([strSynField])) Then

> and

>    SyncCriteria = BuildCriteria(strSynField, dbText,
> Forms!strViewForm!([strSynField]))

> I would appreciate help in getting the correct syntax.

> Thanks, Richard



Tue, 02 Aug 2005 00:01:42 GMT  
 Replacing "Me" in a standard module
Dan,

Thanks for your help, but I still can't get it to work.

I changed the following Me statements from the class
module:
   If IsNull(Me([strSynField])) Then
   SyncCriteria = BuildCriteria(strSynField, dbText, Me
([strSynField]))

To the following in the Standard Module:
'If the SynField is blank in the EditForm, then exit the
Function.
   If IsNull(Forms(strEditForm)!strSynField) Then
'Define the criteria used for the synchronization.
   SyncCriteria = BuildCriteria(strSynField, dbText, Forms
(strViewForm)!strSynField)

When I run the code I get the following error message:
Microsoft Access can't find the field 'strSynField'
referred to in your expression.

I am sure that it is still a syntax problem with the
string variable "strSynField" which in this case is
strSynField = "LastName".

I hope you can give me some additional Help, Richard

Quote:
>-----Original Message-----
>Hi,
>When using string variables to represent a form name,
>use the syntax:

>Forms(strVariable)

>So:
>Forms(strEditForm)!strSynField

>--
>HTH
>Dan Artuso, MVP

>"a problem well stated is a problem half solved"


message

>> I am trying to move code from a Sub in a class (Form)
>> module to a Function in a standard module to be used by
>> multiple Forms in my database. The function is to Close
>> an Edit Form (with only 1 record) and Open a View Form
>> (with many records where edits/deletions/additions are
>> not allowed) at the same record that was just edited.
My
>> problem is getting the syntax correct for replacing
>> a "Me" in the Form Code Module with the correct code in
>> the Standard Code Module. I am using string variables
to
>> define the EditForm, ViewForm, and SyncField. These
>> variables are defined in a Public Module as Public
String
>> variables for general use.

>> The statements (with "Me") that work in the EditForm
>> Module are as follows:
>> 'If the Synch Field is blank, then exit the Sub.
>>    If IsNull(Me([strSynField])) Then
>>       Exit Sub
>>    End If

>> and

>> 'Define the form object and Recordset object for the
View
>> Form.
>>    Set frm = Forms(strViewForm)
>>    Set RS = frm.RecordsetClone

>>    'Define the criteria used for the synchronization.
>>    SyncCriteria = BuildCriteria(strSynField, dbText, Me
>> ([strSynField]))

>> The statements that don't work when I move the code to
>> the Standard Module are as follows:

>>    If IsNull(Forms!strEditForm!([strSynField])) Then

>> and

>>    SyncCriteria = BuildCriteria(strSynField, dbText,
>> Forms!strViewForm!([strSynField]))

>> I would appreciate help in getting the correct syntax.

>> Thanks, Richard

>.



Tue, 02 Aug 2005 05:02:48 GMT  
 Replacing "Me" in a standard module

Quote:

>I changed the following Me statements from the class
>module:
>   If IsNull(Me([strSynField])) Then
>   SyncCriteria = BuildCriteria(strSynField, dbText, Me
>([strSynField]))

>To the following in the Standard Module:
>'If the SynField is blank in the EditForm, then exit the
>Function.
>   If IsNull(Forms(strEditForm)!strSynField) Then
>'Define the criteria used for the synchronization.
>   SyncCriteria = BuildCriteria(strSynField, dbText, Forms
>(strViewForm)!strSynField)

>When I run the code I get the following error message:
>Microsoft Access can't find the field 'strSynField'
>referred to in your expression.

>I am sure that it is still a syntax problem with the
>string variable "strSynField" which in this case is
>strSynField = "LastName".

The same syntax rule applies - When using a string to
identify an element of a collection, use col(string) instead
of col!name.  In your case, it would be:

SyncCriteria = BuildCriteria(strSynField, dbText, _
        Forms(strViewForm)(strSynField))

although you should be careful here.  If the form is bound
to a record source table/query, make sure you understand the
distinction between a field and a control.

--
Marsh
MVP [MS Access]



Wed, 03 Aug 2005 02:05:41 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. CSng(Replace("","","")) = 0.0?

2. How to Replace("String Irregular # of space", "?", "")

3. Using a standard "File open" dialog

4. set "VC++ standard output" a textbox

5. Setting "non-standard" printer object properties

6. "Bas"modules vs. "Class"modules.........

7. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

8. "Replace all "

9. replace null in field with "-"

10. Find Replace "my way"

11. macro for "replace" in word

12. "Replace"-Message doesn't prompt

 

 
Powered by phpBB® Forum Software