Hello guys, I am new to vb programming. Can anyone tell me how to access command button of one form onto another?

I have one mdiParent form on which i have command button "PRINT" and "Add New Client", I want to disable Print button, when i clicked on "Add New Client Button".
Thanks in advance!!!

Dani AI

Generated

As and pointed out, changing the parent form’s button state from the child is a perfectly valid quick fix (and confirmed it worked). A few clarifications and safer patterns make the approach more robust across VB6, VB.NET and Access apps.

Keep the parent responsible for its UI state (don’t directly manipulate another form’s private controls). Example: expose a small public method on the MDI parent that encapsulates the change, then call that from the child. This avoids depending on a control name and keeps compile-time checks clear.

' Parent form (MainForm)
Public Sub SetPrintButtonState(enabled As Boolean)
    cmdPrint.Enabled = enabled
End Sub

' Child form
Dim parentForm = TryCast(Me.MdiParent, MainForm)
If parentForm IsNot Nothing Then
    parentForm.SetPrintButtonState(False)
End If

For looser coupling, raise an event on the child and have the parent handle it (AddHandler / RaiseEvent). This is useful when multiple parents or presenters might host the same child form.

Access-specific note: from an Access form the typical syntax is different — reference the parent form via the Forms collection (for example, Forms("MainForm").Controls("cmdPrint").Enabled = False) or expose a public routine in a standard module/form and call that.

Troubleshooting tips: ensure the parent control is accessible (public or wrapped by a public method), cast Me.MdiParent to the actual parent type in VB.NET, and remember a modal dialog (ShowDialog) already blocks parent interaction so manual disabling is unnecessary. Avoid hard-coded control access from children to reduce maintenance issues.

Recommended Answers

All 3 Replies

mdiParent.cmdPrint.disable -- specify the form.

Hi,

Write this in "Add New" event:

MDIParent.cmdPrint.Enable = False

Later on dont forget to Enable it...

Regards
Veena

Hi,

Write this in "Add New" event:

MDIParent.cmdPrint.Enable = False

Later on dont forget to Enable it...

Regards
Veena

Veena and WaltP you guys are awesome. That code worked well for me. Thanks so much guys!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.