Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Open Form an Add Adjustments
Adrian Connolly 
      
30 days ago
I’m trying to use a form to open another form an input some data an control the second form  objects.
Example o want add a new client. This client can be a individual or business.
The user presses the new client button,  which opens a popup form frmNewclient. From there,
Step 1 # there is a selection of individual or Business, press say the individual button and open which opens the  form “frmClientINDIV” to add in the new client.
Step 2 # Once the  “frmClientINDIV” form is open, I would like to change the forms objects, using VBA as shown below , example Individual, Partnership, Sole biz, company etc,
Private Sub BizStructureFrame_AfterUpdate()
DoCmd.OpenForm "frmClientINDIV"
' opens “frmClientINDIV” form to enter a new record
   'DoCmd.OpenForm "YourFormName", DataMode:=acFormAdd
'if the button is Business then the objects for individual are set to false, while one of ‘them is repositioned and resized
If BizStructureFrame <> 1 Then
    Form.frmClientINDIV.Title.Visible = False
    Form.frmClientINDIV.Label3.Visible = False
    Form.frmClientINDIV.FirstName.Visible = False
    Form.frmClientINDIV.Label4.Visible = False
    Form.frmClientINDIV.MiddleName.Visible = False
    Form.frmClientINDIV.Label5.Visible = False
End If
Select Case BizStructureFrame
    Case 1
       'ME.RecordSource = SELECT * FROM dbtClient WHERE (IsCorporate = False) ORDER BY MainName, FirstName;
        Forms!frmClientINDIV!IsCorporate = False
        Form.frmClientINDIV.ContactLabel.Caption = "INDIVIDUAL"
        Form.frmClientINDIV.MainName.Left = 4926.096 '8.688cm
        Form.frmClientINDIV.MainName.Width = 1584.198  '2.794cm
            'individual fields shown if business
            Form.frmClientINDIV.Title.Visible = True
            Form.frmClientINDIV.Label3.Visible = True
            Form.frmClientINDIV.FirstName.Visible = True
            Form.frmClientINDIV.Label4.Visible = True
            Form.frmClientINDIV.MiddleName.Visible = True
            Form.frmClientINDIV.Label5.Visible = True
    Case 2
      ME.RecordSource = SELECT * FROM dbtClient WHERE (((IsCorporate)=True)) ORDER BY MainName;
        Forms!frmClientINDIV!IsCorporate = True
        Form.frmClientINDIV.ContactLabel.Caption = "SOLE PROPRIETTORSHIP"
         Form.frmClientINDIV.MainName.Left = 1757.7  '1.143cm
         Form.frmClientINDIV.MainName.Width = 4752.027  '8.381cm
End Select
End Sub
close ““frmNewclient.”” form

Donald Blackwell  @Reply  
       
30 days ago
Adrian

Does the code work for you or is there something we can help with?

You've said what you're trying to do and shown code that applies but you didn't indicate if you were just showing what youve done or if something isn't working. And, if not what isn't working, what errors do you get, etc.
Adrian Connolly OP  @Reply  
      
30 days ago
the code gets stuck from         Form.frmClientINDIV.ContactLabel.Caption = "INDIVIDUAL" onwards | with a run-time error 2465: application defined or object defined error.
Mind you this worked on the frmclientindiv form but not control through a another form
Donald Blackwell  @Reply  
       
30 days ago
Ahh, that explains it ;)

        Forms!frmClientINDIV!IsCorporate = False
        Form.frmClientINDIV.ContactLabel.Caption = "INDIVIDUAL"


Notice the difference in the lines of code after the IsCorporate = False line:

You went from having Forms bang (Forms!) to Form dot (Form.)

The bang indicates you're referencing a different form. The Form. refers to the current form you're on. So:

Forms!frmClientINDIV!IsCorporate = False --- tells Access/VBA to look for an open form (frmClientINDIV) and set a control (IsCorporate) to false.

Form.frmClientINDIV.ContactLabel.Caption = "Individual" tells Access/VBA to look for a control or property (frmClientINDIV) on the current form with a property (ContactLabel) and activate a method/event (Caption) with a value of "INDIVIDUAL".

If you change all of the Form. to Forms! you should see better results:

        Forms!frmClientINDIV!ContactLabel.Caption = "INDIVIDUAL"
        Forms!frmClientINDIV!MainName.Left = 4926.096 '8.688cm
        Forms!frmClientINDIV!MainName.Width = 1584.198  '2.794cm


Donald Blackwell  @Reply  
       
30 days ago
Also, you could reduce duplication and, IMO, make your code easier to read if you use a "With" Block:

Private Sub BizStructureFrame_AfterUpdate()
    
     DoCmd.OpenForm "frmClientINDIV"
' opens "frmClientINDIV" form to enter a new record
   'DoCmd.OpenForm "YourFormName", DataMode:=acFormAdd
'if the button is Business then the objects for individual are set to false, while one of 'them is repositioned and resized

     With Forms!frmClientINDIV
          If BizStructureFrame <> 1 Then
               !Title.Visible = False
               !Label3.Visible = False
               !FirstName.Visible = False
               !Label4.Visible = False
               !MiddleName.Visible = False
               !Label5.Visible = False
          End If
          Select Case BizStructureFrame
               Case 1
               'ME.RecordSource = SELECT * FROM dbtClient WHERE (IsCorporate = False) ORDER BY MainName, FirstName;
                    !IsCorporate = False
                    !ContactLabel.Caption = "INDIVIDUAL"
                    !MainName.Left = 4926.096 '8.688cm

... The Rest of your code


     End With

End Sub


Adrian Connolly OP  @Reply  
      
29 days ago
thanks, i did try that approach but still had the same result, then i placed the code in brackets, Forms("frmClientINDIV")("FirstNameLab").Visible = False
when true it works, but as a false narative runtime error 2165 ýou can't hide a control that has the focus'
Donald Blackwell  @Reply  
       
29 days ago
Yeah, Access won't let you hide a control that has focus so that field probably gets focus when your form opens. To get around that, you can move the focus to a different field before you start hiding controls:

Forms(YOURFORM)(ACONTROLTHATWILLREMAINVISIBLE).setFocus

Then continue hiding controls.
Adrian Connolly OP  @Reply  
      
28 days ago
is there a sample to look at as that did not appear to work. sorry to bother you, i don't what the hell i'm doing wrong
Donald Blackwell  @Reply  
       
28 days ago
Hmm, did you get any errors when you tried it? The one thing I omitted, replace YOURFORM with the name of your form, and ACONTROLTHATHWILLREMAINVISIBLE with the name of a control on that formand, and, doh, I didin't put those in quotes, as I should have.

So to move more to your form's naming:

Forms("frmClientINDIV")("ACONTROLTHATWILLREMAINVISIBLE").SetFocus

Another option so you don't have to worry about which controls are going to be visible depending on the state of the business, for instance, Individual, Partnership, etc., you could put a transparent button on the form somewhere. I usually put it as the first control in the tab order, that way, once I've hidden fields and shown fields, as soon as the user presses tab, they'll go to the first visible control.

So then, right after the form opens, for example, if you have a transparent button named "FocusBtn":

Forms("frmClientINDIV")("FocusBtn").SetFocus

Then let your code hide and show controls as needed while that button has focus. You could even add another SetFocus at the end of each section to move the Focus to the first visible field if you wanted so the user isn't confused.

Donald Blackwell  @Reply  
       
28 days ago
Ugh, sorry, don't know why I clicked Bold instead of Code that last time :(
Kevin Robertson  @Reply  
          
27 days ago
Fixed it for you Donald
Adrian Connolly OP  @Reply  
      
27 days ago
thanks, sorry i could not see the trees for the forest
Add a Reply Upload an Image
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: 8/7/2026 11:26:52 AM. PLT: 0s