On Click Function Open Different Forms

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

I need to create a button, that, when clicked will open a data entry
form based on the current records unique ID#. I need help with the
code to make that happen.

Further Information:
I will open my clients form and look up a particular client. I would
like to then click a button called "Create New Ticket" and have the
form which was specifically designed for that client open up. Each
new ticket form is named based on the client (for example, Client
ID#1234 has a corresponding "NewTicket_ClientID1234" Form.

Form to place the button on: FRM_Clients, unique field: ClientID
Form to open (in ADD mode): NewTicket_ClientIDXXXX
 
Michael

As an alternate approach, since it sounds like a "client" could have
multiple "tickets", you could use a main form (for the client info) and a
subform (for the tickets). With this design, you wouldn't need to "pop
open" a new form. A new ticket could just be added to the subform.

Good luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
Thank you for the suggestion. However, I have to use the "pop-up"
form. I am dealing with data entry clerks who need things nice and
neat and very well explained so we need the pop up form to be more
detailed and have more explanations than what a sub-form can offer.

Can you suggest how to make the pop-up form idea work?
 
Michael

I believe you can simply add a command button to your (main) form in design
view. The wizard will guide you through setting up what that click will do
(i.e., open another form).

Good luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
Jeff,
That wizard only walks you through opening one form. I need a
button that will open different forms based on the client number,
i.e., newticketformXXX where XXX is the client id of the current form.
 
Jeff,
That wizard only walks you through opening one form. I need a
button that will open different forms based on the client number,
i.e., newticketformXXX where XXX is the client id of the current form.

Do you have a different *FORM* - different layout, different fields - for each
client? Or just different data laid out in the same way? Different forms would
be unusual but could certainly be managed, but it's a whole lot more
complicated! Please explain.
 
I am far from an Access VB guru but somehow I figured it out myself.
Below is the code I used for anyone else who may need to do this same
thing:

Private Sub NewTicketForm_Click()
On Error GoTo Err_NewTicketForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "NewTicket" & "" & Me.ClientID & ""
DoCmd.OpenForm stDocName, , , acFormAdd

Exit_NewTicketForm_Click:
Exit Sub

Err_NewTicketForm_Click:
MsgBox Err.Description
Resume Exit_NewTicketForm_Click

End Sub
 
Michael said:
I am far from an Access VB guru but somehow I figured it out myself.
Below is the code I used for anyone else who may need to do this same
thing:

Private Sub NewTicketForm_Click()
On Error GoTo Err_NewTicketForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "NewTicket" & "" & Me.ClientID & ""
DoCmd.OpenForm stDocName, , , acFormAdd

Exit_NewTicketForm_Click:
Exit Sub

Err_NewTicketForm_Click:
MsgBox Err.Description
Resume Exit_NewTicketForm_Click

End Sub

That's a good solution if you only have a few clients but John's question is
something you should answer.
Managing a few hundred different forms would be a problem and we will not
talk about a few thousand clisnt's.
 
I am far from an Access VB guru but somehow I figured it out myself.
Below is the code I used for anyone else who may need to do this same
thing:

Private Sub NewTicketForm_Click()
On Error GoTo Err_NewTicketForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "NewTicket" & "" & Me.ClientID & ""
DoCmd.OpenForm stDocName, , , acFormAdd

Exit_NewTicketForm_Click:
Exit Sub

Err_NewTicketForm_Click:
MsgBox Err.Description
Resume Exit_NewTicketForm_Click

End Sub

Thanks for posting back, but I'm still totally baffled why each client should
have a separate Access Form object! That seems like a very strange design; if
you have 318 clients do you have 318 *differently structured forms*? Do you
build a whole new form every time you get a new client? What's different about
these forms?

One tiny simplification: there is no need to concatenate an empty string
before or after the clientID value; appending an empty string to a string does
nothing, just like adding 0 to a number leaves the result unchanged. Your
expression could be just

stDocName = "NewTicket" & Me.ClientID
 
I'll echo what Mike P. and John V. have said ... a separate form for each
client is ... unusual ... in a well-normalized relational database.

The primary reason for using a separate form for each would be that each
Client had totally different things being stored about them. For example,
if ClientA had a birthdate and a street address, and ClientB had a Dog'sName
and phone number, and ClientC had a AnnualSalary and ... You get the idea.

On the other hand, if each/every client had all/most of:
LastName
FirstName
StreetAddress
City
State
PostalCode
DateOfBirth

then you would only need ONE form, and would only need ONE table.

We haven't focused on your underlying data structure (i.e. tables) because
you were focusing on forms ... but it all STARTS with the data.

More info, please...

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
Back
Top