MrExcel Publishing
Your One Stop for Excel Tips & Solutions

multiple commandbuttons on a form....


Posted by Mark on January 14, 2002 8:53 AM

I have a form (main.frm) that has that has five command buttons that opens five other forms. I can code one of the buttons to open a form, but can't get the other four to accept the frm___.show code. How do I get this to work correctly??

more info:
the commandbuttons on the "main" form are
-RFI, for rfi.frm (works)
-changeorder, for changeorder.frm (doesn't work)
-invoice, for invoice.frm (doesn't work)
-transmittal, for transmittal.frm (doesn't work)
-addjob, for addjob.frm (doesn't work)

I'm greatful for any help. As you can tell, this is my 1st VBA project.

Thanks,
Mark


Posted by Jerid on January 14, 2002 12:22 PM

Can you share your code with everyone? (NT)

.

Posted by Mark on January 14, 2002 12:38 PM

I'll be glad to once I get it working**


Posted by Jerid on January 14, 2002 12:42 PM

Re: I'll be glad to once I get it working**

We can't help you unless you give an example of your current, not working, code.

Posted by Mark on January 14, 2002 12:56 PM

Duhh, I see your point.....

here's the code. I've only begun to start writing the code, so there's not much to it.

__________________________________________

Private Sub Addjob_Click()
Addjob.Show
End Sub

Private Sub Changeorder_Click()
changerorder.Show
End Sub

Private Sub invoice_Click()
invoice.Show
End Sub

Sub RFIbutton_Click()
RFI.Show
End Sub

Sub Trans_Click()
Transbutton.Show
End Sub

___________________________________

Thanks,
the airhead


Posted by Jerid on January 14, 2002 1:01 PM

Try this

This might help you get answers faster on this and other message boards.
http://www.mvps.org/access/netiquette.htm#Asking

Are far as your problem goes you need to have 5 different click events, one for each command button. The EventName should be the command buttons name, an underscore, followed by Click() (Example: command1_click())


Sub RFI_Click()
RFI.Show
End Sub

Sub ChangeOrder_Click()
ChangeOrder.Show
End Sub

Sub Invoice_Click()
Invoice.Show
End Sub

Sub Transmittal_Click()
Transmittal.Show
End Sub

Sub AddJob_Click()
AddJob.Show
End Sub

Good Luck

Jerid

Posted by Jerid on January 14, 2002 1:03 PM

Re: Duhh, I see your point.....

How can I block the print and save functions in Excel. I have an invoice program that want to control the printing from my own macro as well as saving. Is there a way to do this and if so how?

Any help would be appreciated,

John

Posted by Jerid on January 14, 2002 1:08 PM

Re: Duhh, I see your point.....

Did you rename all of the command buttons? Not the Captions, the Name property.

Posted by Mark on January 14, 2002 1:14 PM

Yes, same as in the subs**

Posted by Jerid on January 14, 2002 1:19 PM

What happens when you click the button? (NT)

.

Posted by Mark on January 14, 2002 1:32 PM

Re: What happens when you click the button? (NT)

I get a compile error:
"method or data member not found"

Posted by Jerid on January 14, 2002 1:39 PM

Do you have any code in the forms? (NT)

Do you have any code in the forms?

Posted by Mark on January 14, 2002 1:46 PM

Re: Do you have any code in the forms? (NT)

frmaddjob
Public enteredaddjob As Boolean

Sub datasave()
'
' datasave Macro
' Macro recorded 01-09-2002 by Mark A. Lowe
'

'
Dim jobnumber As Integer
Dim pono As Integer
Dim Jobname As Integer
Dim amount As Integer
Dim est As Integer
Dim jobloc As Integer
Dim fablist As Integer
Dim contractorname As Integer
Dim conadd1 As Integer
Dim conadd2 As Integer
Dim conphone As Integer
Dim confax As Integer
Dim super As Integer
frmaddjob.Show


If addjobbutton Then
jobnumber = frmaddjob.jobnumber.Text
pono = frmaddjob.pono.Text
Jobname = frmaddjob.Jobname.Text
jobloc = frmaddjob.jobloc.txt
amount = frmaddjob.amount.Text
est = frmaddjob.est.Text
fablist = frmaddjob.fablist.Text
contractorname = frmaddjob.contractorname.Text
conadd1 = frmaddjob.conadd1.Text
conadd2 = frmaddjob.conadd2.Text
conphone = frmaddjob.conphone.Text
confax = frmaddjob.confax.Text
super = frmaddjob.super.Text

jobnumber = Sheets("data").Range("p1").Value
Sheets("data").Range("a65536").End(xlUp).Offset(1, 0).Value = jobnumber
pono = Sheets("data").Range("p2").Value
Sheets("data").Range("b65536").End(xlUp).Offset(1, 0).Value = pono
amount = Sheets("data").Range("p3").Value
Sheets("data").Range("e65536").End(xlUp).Offset(1, 0).Value = amount
est = Sheets("data").Range("p3").Value
Sheets("data").Range("f65536").End(xlUp).Offset(1, 0).Value = est
Jobname = Sheets("data").Range("p4").Value
Sheets("data").Range("c65536").End(xlUp).Offset(1, 0).Value = Jobname
jobloc = Sheets("data").Range("p5").Value
Sheets("data").Range("d65536").End(xlUp).Offset(1, 0).Value = jobloc
fablist = Sheets("data").Range("p6").Value
Sheets("data").Range("m65536").End(xlUp).Offset(1, 0).Value = fablist
contractorname = Sheets("data").Range("p7").Value
Sheets("data").Range("g65536").End(xlUp).Offset(1, 0).Value = contractorname
confax = Sheets("data").Range("p7").Value
Sheets("data").Range("k65536").End(xlUp).Offset(1, 0).Value = confax
conphone = Sheets("data").Range("p7").Value
Sheets("data").Range("j65536").End(xlUp).Offset(1, 0).Value = conphone
conadd1 = Sheets("data").Range("p7").Value
Sheets("data").Range("h65536").End(xlUp).Offset(1, 0).Value = conadd1
conadd2 = Sheets("data").Range("p8").Value
Sheets("data").Range("i65536").End(xlUp).Offset(1, 0).Value = conadd2
super = Sheets("data").Range("p9").Value
Sheets("data").Range("l65536").End(xlUp).Offset(1, 0).Value = super
Else
End
End If

Range("P1:P20").Select
Selection.ClearContents
Range("P1").Select
End Sub

Private Sub cancelbutton_Click()
Main.Show
Addjob.Hide
End Sub

Private Sub newfabbutton_Click()
addfab.Show
End Sub

Private Sub UserForm_Click()

End Sub
________________________________

frmchangeorder
no code
________________________________

frminvoice
no code
________________________________

frmrfi

Private Sub cancelbutton_Click()
RFI.Hide

________________________________

frmmain

Private Sub Addjob_Click()
Addjob.Show
End Sub

Private Sub Changeorder_Click()
changerorder.Show
End Sub

Private Sub invoice_Click()
invoice.Show
End Sub

Private Sub Label6_Click()

End Sub

Private Sub MultiPage1_Change()

End Sub

Sub RFIbutton_Click()
RFI.Show
End Sub

Sub Trans_Click()
Trans.Show
End Sub

Private Sub UserForm_Click()

End Sub

________________________________

trans
no code
________________________________


like I said, there's not that much there. Does this help??

Mark

Posted by Jerid on January 14, 2002 2:00 PM

Re: Do you have any code in the forms? (NT)

You should put a breakpoint on the first line of your click event (Select the line and press F9), then click the button, the VBE will stop on that line of code, now step through your code one line at a time by pressing F8 until you get the error. Once we find that needle we will have a place to start.

Posted by Mark on January 14, 2002 2:28 PM

OK, I found the problem.....

Well, I didn't find the problem, I just stared from scratch & renamed the command buttons. works fine, everything opens.

Question:
I open form "addjob" with a commandbutton on the "main" form. Once the "addjob" form is open, I have another commandbutton on "addform" that opens another form, "addfabricator".

here's the code that opens the "addjob" from the "main" form...

Private Sub Addjobcommandbutton_Click()
Addjob.Show
End Sub

form "addjob opens", I now open form "addfab" with a commandbutton on form "addjob". Here's the code for that function...

Private Sub newfabbutton_Click()
addfab.Show
End Sub

form "addfab" opens. When I hit a commandbutton on the "addfab" for, it closes. here's the code...

Private Sub fabcancelbutton_Click()
addfab.Hide

End Sub

I'm now back on the "addjob" form. I have a cancel commandbutton that should close the "addjob" form & return to the "main" form, but when I hit the cancel commandbutton, I get this error message. "Run-time error '400':
Form already displayed; can't show modally"

here's the code...

Private Sub cancelbutton_Click()
Main.Show
Addjob.Hide
End Sub

I know that using the .hide function is the problem, but what;s the solution.

Thanks, you've been a huge help already.

Mark

Posted by Jerid on January 15, 2002 5:44 AM

Re: OK, I found the problem.....

(Your Code )

Private Sub Addjobcommandbutton_Click()
Addjob.Show
End Sub

Private Sub newfabbutton_Click()
addfab.Show
End Sub

Private Sub fabcancelbutton_Click()
addfab.Hide
End Sub

Private Sub cancelbutton_Click()
Main.Show
Addjob.Hide
End Sub

I don't see you closing or hiding Main anywhere, so you should need the line Main.Show in the last procedure. If you are hiding it somewhere, then you should use Main.Visible = True, not Main.Show If Main is already loaded, you can't load it again.

Jerid