Solved Change NAME in VBA (1 Viewer)

ClaraBarton

Registered User.
Local time
Today, 05:27
Joined
Oct 14, 2019
Messages
463
Years ago when I knew even less than I do now, I used NAME as a field name in a small db. I'm updating the database and I've gone back through all the tables in the BE and removed or changed the name on those fields. I've also done a deep search on the FE and corrected everything I can find. However... Whenever I use me.Name in VBA it corrects to me.NAME which isn't the same thing. It errors and I can't fix it. I have no idea how to fix this. I used V-tools to search and replace but VBA changes it all back to NAME.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:27
Joined
Oct 29, 2018
Messages
21,473
VBA is normally not case sensitive, so that shouldn't matter. What do you mean that me.Name and me.NAME are not the same thing? You know Me.Name refers to the name of the form you're in, right?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:27
Joined
May 21, 2018
Messages
8,529
See if this is the same

My guess in your case you still have a control named NAME.
To test that type Me.NAME. (see what intellisense brings up)
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:27
Joined
May 21, 2018
Messages
8,529
Here is the point.
If you had a field called NAME and you created a form and added that field to the form, by default the control is called NAME. You can do whatever you want to the tables it will have not impact the existing control names. If you did not manually go back and change the control, you will still have a control named NAME. Find and replace cannot fix that either.
 

ClaraBarton

Registered User.
Local time
Today, 05:27
Joined
Oct 14, 2019
Messages
463
Well, in this case it is case sensitive.
Code:
Private Sub btnClose_Click()
    DoCmd.Close acForm, Me.NAME

    If CallingForm = "" Then
        DoCmd.OpenForm "frmAOpen"
    Else
    
    Dim frm As Form
        For Each frm In Application.Forms
            If frm.NAME = CallingForm Then
                 DoCmd.OpenForm CallingForm
         Exit For
            End If
        Next frm
    End If
    
End Sub
This says it's an invalid reference to the parent property. There is no parent, it is a single form.
Me.NAME. shows nothing; I searched through the object browser and I couldn't find anything.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:27
Joined
Feb 28, 2001
Messages
27,186
As a further note, since the auto-correction is to upper-case NAME, the thing you seek is DEFINED in upper case as well. This happens A LOT if you use the ENUM style of declaring certain constants and start confusing the capitalization between declaration and use.
 

ClaraBarton

Registered User.
Local time
Today, 05:27
Joined
Oct 14, 2019
Messages
463
Ok, valid point. I'll search all forms for control name. I didn't realized they wouldn't be found.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:27
Joined
May 21, 2018
Messages
8,529
Code:
Public Sub FindControl()
  Dim ctrl As Access.Control
  Dim frm As Access.Form
  Dim obj As AccessObject
  For Each obj In CurrentProject.AllForms
    DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
      Set frm = Forms(obj.Name)
      For Each ctrl In frm
        If ctrl.Name = "NAME" Then Debug.Print "Control " & ctrl.Name & " Found in " & frm.Name
      Next ctrl
      DoCmd.Close acForm, obj.Name
  Next obj
End Sub
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 22:27
Joined
Jan 20, 2009
Messages
12,852
I've also done a deep search on the FE and corrected everything I can find.
Are you referring to the V-tools Deep Search? It would have found it in the forms.
Best tool ever for this task and completely free.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:27
Joined
May 7, 2009
Messages
19,245
maybe re-arrange your code:
Code:
Private Sub btnClose_Click()

    If CallingForm = "" Then
        CallingForm = "frmAOpen"
    End If
    
    On Error Resume Next
    DoCmd.OpenForm CallingForm
    
    DoCmd.Close acForm, Me.NAME

End Sub
 

ClaraBarton

Registered User.
Local time
Today, 05:27
Joined
Oct 14, 2019
Messages
463
I didn't see your sub, Majp so I went through EVERY stinking form and EVERY report and I found a couple stray Name's but no NAMES. I fixed them all, decompiled, AND IT IS FIXED!!!! All the references in VBA automatically changed to Me.Name and Thank you all very much for your time!!!!
 

ClaraBarton

Registered User.
Local time
Today, 05:27
Joined
Oct 14, 2019
Messages
463
Arnelgp... I asked earlier if it mattered. The consensus was that it doesn't (unless I'm filling variables from the closing form) and I read somewhere that you should close first. Which is it?
Well duh! just answered my own question, didn't I?
 
Last edited:

Users who are viewing this thread

Top Bottom