One form for Add and View

CEH

Curtis
Local time
Today, 13:11
Joined
Oct 22, 2004
Messages
1,187
This one should be easy to me by now.... But today I think I'm having a "blonde moment" :)
I have a Client Contact form.... Different command buttons... first for "Contracts" one button to Add a contract, another to view contracts for that client. These work fine....... BUT... I am using 2 different forms for this on.
The next two command buttons are for "Appointments" One to add an appointment, another to view any appointments for this Client. Same form on these two command buttons.......
I have searched but cannot find any examples of using the same form for "add" and "View"....... I'm thinking I just have my syntax on the Docmd.OpenForm and criteria messed up.... But I would like to see an example of it done correctly. Can someone point me in the right direction???

Thanks
 
You need to add an "OpenArgs" to each of the buttons one say "New" the other "View", then you need to put a logical test on the "On Load" event of the form and switch on or off the add data and edit data properties of the form.
 
I think you can have that easier.

What I did in a similar case was to provide different arguments to the form via the command buttons, and then the same form can be used for adding data or for browsing.

For adding data:

Private Sub YourButton_OnClick (NewData As String, Response As Integer)

Dim stDocName As String
stDocName = "YourForm"

DoCmd.OpenForm stDocName, acNormal, , , acFormAdd, acDialog

End Sub

"acDialog" acts like the "modal" switch so the form will stay in the foreground until closed; you may not need that.

And just for browsing you can change the DoCmd line as follows:

DoCmd.OpenForm stDocName, acNormal, , , acFormReadOnly
 

Users who are viewing this thread

Back
Top Bottom