Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple questions on forms ... 2

Status
Not open for further replies.
Jun 4, 2003
18
GB
(1) i want to create a button that will open to things at once - two different reports. can anyone tell me how to do this? i couldnt find it in the wizard, but maybe im being thick ..

(2) when the user clicks a button on a form to open another form, i want the original form to close. then when the user closes the second form, i want the original form to open again. any ideas?

ta

CharlotteR
 
Charlotte,

1)
Sub test()

DoCmd.OpenReport "Report1", acViewPreview
DoCmd.OpenReport "Report2", acViewPreview

End Sub

2)
Rather than close the form, why not just hide it behind the second form, i.e let your second form open over the top of it.

Good luck

ps Access comes with a "solutions.mdb" database that has a lot of more technical detail on it. It does not load with a standard install but can be found on the CD or with a custom install - it's good.
 
thanks - that makes sense, but i diodnt create the database, so have no idea how to get into the SQL part of it. or do i just need to go into the VB part of it? this is the vb code i have for that button at the moment (created by the wizard):

Private Sub Command30_Click()
On Error GoTo Err_Command30_Click

Dim stDocName As String

stDocName = "Summary"
DoCmd.OpenReport stDocName, acPreview

Exit_Command30_Click:
Exit Sub

Err_Command30_Click:
MsgBox Err.Description
Resume Exit_Command30_Click

End Sub

whereabouts should i insert it? ta very much!
 
Charlotte,

This code is generated by Access, so you'll need to modify it slightly.

Private Sub Command30_Click()
On Error GoTo Err_Command30_Click

Dim stDocName, stDocName2 As String

stDocName = "Summary"
stDocName2 = "Something_Else"
DoCmd.OpenReport stDocName, acPreview
DoCmd.OpenReport stDocName2, acPreview

Exit_Command30_Click:
Exit Sub

Err_Command30_Click:
MsgBox Err.Description
Resume Exit_Command30_Click

End Sub

 
thank u!! it works wonderfully!

just trying to find a solution to the second prob now!

cheers
 
I agree with CharlotteR. I would hide/show the forms rather than open/close them, but if you have to open/close them, try the following:

To open another form and close the current, create a button and put this in it's OnClick module:

Code:
Private Sub butOpenFORM2_Click()

     DoCmd.OpenForm "[i]FORM1[/i]"
     DoCmd.Close acform, "[i]FORM2[/i]"

End Sub

-------------------------
To reopen the original form when FORM2 is closed, put this in the FORM2's On Close module:

Code:
Private Sub Form_Close()

     DoCmd.OpenForm "[i]FORM1[/i]"
     DoCmd.Close acform, "[i]FORM2[/i]"

End Sub
 
thanks to u all that helped. i have now found this on advisor.com:

Listing 1: Open and shut case -- The main form closes itself as it opens the second form while the second form opens the main form as it's unloaded.

'In the main (switchboard) form:

Private Sub cmdOpen1_Click()
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "Form1"
End Sub

'In the second form:

Private Sub Form_Unload(Cancel As Integer)
DoCmd.OpenForm "frmSwitchboard"
End Sub

a slightly alternative way ... its all working now ta
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top