Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Docmd Rename Form
Howard Chapell 
    
7 months ago
I am getting "Invalid procedure or Argument when trying to rename a form. My Code is as follows

DetailsPrivate Sub BuildJobsListForm()
    On Error GoTo ErrHandler

    Dim frm As Form
    Set frm = CreateForm
    frm.Caption = "Jobs List"
    frm.RecordSource = "Jobs"

    Private Sub BuildJobsListForm()
    On Error GoTo ErrHandler

    Dim frm As Form
    Set frm = CreateForm
    frm.Caption = "Jobs List"
    frm.RecordSource = "Jobs"

    ' --- Listbox: Job Overview ---
    Dim ctlList As Control
    Set ctlList = CreateControl(frm.Name, acListBox)
    With ctlList
        .Name = "lstJobs"
        .RowSource = "SELECT JobID, JobDescription, Status, DueDate FROM Jobs"
        .ColumnCount = 4
        .ColumnHeads = True
        .Top = 600
        .Left = 600
        .Width = 6000
        .Height = 3000
    End With

    ' --- Refresh Button ---
    Dim btn As Control
    Set btn = CreateControl(frm.Name, acCommandButton)
    With btn
        .Name = "btnRefresh"
        .Caption = "Refresh List"
        .Top = 3800
        .Left = 600
        .Width = 2000
        .Height = 400
        .OnClick = "=Requery()"
    End With

    ' Save, close, rename safely
    DoCmd.Save acForm, frm.Name
    DoCmd.Close acForm, frm.Name
    DoCmd.Rename "frmJobsList", acForm, frm.Name

    Exit Sub

    ' --- Refresh Button ---
    Dim btn As Control
    Set btn = CreateControl(frm.Name, acCommandButton)
    With btn
        .Name = "btnRefresh"
        .Caption = "Refresh List"
        .Top = 3800
        .Left = 600
        .Width = 2000
        .Height = 400
        .OnClick = "=Requery()"
    End With

    ' Save, close, rename safely
    DoCmd.Save acForm, frm.Name
    DoCmd.Close acForm, frm.Name
    DoCmd.Rename "frmJobsList", acForm, frm.Name

    Exit Sub
Donald Blackwell  @Reply  
       
7 months ago
You've duplicated that first several lines of code:

Not sure if you pasted duplicates or you've actually duplicated your code inside.

You have to procedure declarations and all the code is duplicated throughout and you don't have and end sub anywhere in what you posted.
Donald Blackwell  @Reply  
       
7 months ago
The 1st 6 lines duplicate before the 'Listbox comment

Then, after the 1st 'Save, close rename safely comment, you duplicate the refresh and save code.

Also, It should be "End Sub" not "Exit Sub"

Exit sub is used when you want to exit the procedure from within a control structure such as an if-then-end if.
Kevin Yip  @Reply  
     
7 months ago
Howard  After you close the form, the frm object becomes nothing, so frm.Name becomes invalid.  That's why the Rename command returns an error.  You need to save frm.Name into a variable first before closing the form.
Raymond Spornhauer  @Reply  
          
7 months ago
Howard

Donald is correct.

    Dim frm As Form
    Set frm = CreateForm
    frm.Caption = "Jobs List"
    frm.RecordSource = "Jobs"

    Private Sub BuildJobsListForm()
    On Error GoTo ErrHandler

    Dim frm As Form
    Set frm = CreateForm
    frm.Caption = "Jobs List"
    frm.RecordSource = "Jobs"


Duplicate Code.

-Raymond
Howard Chapell OP  @Reply  
    
7 months ago
Yes I copied the refresh button mistakenly twice. Thankls ever so much everyone for your input I really apprecdiate it

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 3:59:56 PM. PLT: 1s