button to switch forms?

W

wacntn

I have two forms and I want the user to be able to switch back and forth
between them. The forms use data from the same table and from only one
table. I have a button working on one form to go to the other form and to
'stick' to the record the user is on. But, when I try to do this on the
other form to go back, I get an error I can't track down following MS's
directions. Here's my code for the button. The error follows.

Private Sub Command2068_Click()
On Error GoTo Err_Command2068_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmProject Portfolio Maintenance"

stLinkCriteria = "[ProjectID]=" & "'" & Me![ID] & "'"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command2068_Click:
Exit Sub

Err_Command2068_Click:
MsgBox Err.Description
Resume Exit_Command2068_Click

End Sub

The following is in the msgbox that pops up when the button is clicked.

The expression On Click you entered as the event property setting produced
the following error:
Procedure declaration does not match description of event or procedure
having the same name.

Procedure].

* There may have been an error evaluating the function, event, or macro.
 
F

fredg

I have two forms and I want the user to be able to switch back and forth
between them. The forms use data from the same table and from only one
table. I have a button working on one form to go to the other form and to
'stick' to the record the user is on. But, when I try to do this on the
other form to go back, I get an error I can't track down following MS's
directions. Here's my code for the button. The error follows.

Private Sub Command2068_Click()
On Error GoTo Err_Command2068_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmProject Portfolio Maintenance"

stLinkCriteria = "[ProjectID]=" & "'" & Me![ID] & "'"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command2068_Click:
Exit Sub

Err_Command2068_Click:
MsgBox Err.Description
Resume Exit_Command2068_Click

End Sub

The following is in the msgbox that pops up when the button is clicked.

The expression On Click you entered as the event property setting produced
the following error:
Procedure declaration does not match description of event or procedure
having the same name.

Procedure].

* There may have been an error evaluating the function, event, or macro.

What is the datatype of [ProjectID]?
Your syntax suggests it is Text datatype.
If it is a Number datatype then use:

stDocName = "frmProject Portfolio Maintenance"
stLinkCriteria = "[ProjectID]= " & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name

In any event, move the DoCmd.Close to after you open the second form.
And you should specify which form. Me.Name will close the form on
which this code is placed.
 
J

John Welch

This isn't really answering your question, but it might help.
Do you really need to close and reopen the two forms? Could you just make
them visible and invisible? Could you use just one form with a tab control
to show multiple pages?
just food for thought, forgive if you've already dismissed those solutions
-John


C
 
W

wacntn

I'd love to keep it simple. I just don't know enough about programming in
VBA in Access to do anything fancy. I don't do this enough to get really
good at it. You'd think the books I have would have a simple example or at
least explain how to do this. Can you give me a tutorial?

This isn't a fancy, polished application. I just want this to be simple for
users though.

I want to toggle between two forms and stay on the same record. What does
it take? The forms refer to the same table and only that table. They are
called frmProject Portfolio Maintenance and frmProject Portfolio Status
Tracking. I am more than willing to throw out my code for something better
and simpler!

Thanks for all your help!

Walter
John Welch said:
This isn't really answering your question, but it might help.
Do you really need to close and reopen the two forms? Could you just make
them visible and invisible? Could you use just one form with a tab control
to show multiple pages?
just food for thought, forgive if you've already dismissed those solutions
-John


C
wacntn said:
I have two forms and I want the user to be able to switch back and forth
between them. The forms use data from the same table and from only one
table. I have a button working on one form to go to the other form and
to 'stick' to the record the user is on. But, when I try to do this on
the other form to go back, I get an error I can't track down following
MS's directions. Here's my code for the button. The error follows.

Private Sub Command2068_Click()
On Error GoTo Err_Command2068_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmProject Portfolio Maintenance"

stLinkCriteria = "[ProjectID]=" & "'" & Me![ID] & "'"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command2068_Click:
Exit Sub

Err_Command2068_Click:
MsgBox Err.Description
Resume Exit_Command2068_Click

End Sub

The following is in the msgbox that pops up when the button is clicked.

The expression On Click you entered as the event property setting
produced the following error:
Procedure declaration does not match description of event or procedure
having the same name.

Procedure].

* There may have been an error evaluating the function, event, or macro.
 
G

Guest

I have a command button which opens another form which is bound to the same
table.

I create the second forms through the form wizard and include the fields I
need, which includes, in my case, the reference number.

When I place the command button on my original form I choose Form Operations
and Open Form.

It then asks which form to open (the new one), and then (this is the key)
whether to open the form and display all records or to open and find specific
data to display.

I choose sepcific data and it asks which fields have matching data. In my
case, I select reference no on both sides. It then finishes creating the
button as normal.

Now when I click that button from the first form it bring me to the new form
on the same record.

I know, I use too many words.

hth

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top