Staying on the same record ID when switching forms

Jim976

New member
Local time
Yesterday, 16:29
Joined
Nov 26, 2013
Messages
3
Hey, Everyone.

My issue is simple - I just need a little piece of code.

Two forms have matching fields (ContractID), and each form has different data displayed from different tables (SQL views, actually).

I want Access 2007 to stay on the same ContractID when the user switches to a different form.

The Event Procedure has to be simple - could someone figure this out for me?

Thanks for the help.
 
Where are you getting the ID from?

Are you opening the second Form from the First?

You could refer to it using
FORMS!frmNAME!ContractID
 
Hey, Alex.

Each form is using a primary table with the ContractID as the primary key, with other tables or views connected to the primary table.

I have a command button on the first form to open the second form.

I've tried using:

Public Sub B_AspenInfo1_Click()
DoCmd.OpenForm "Form-AspenInfo", acNormal, , "[dbo_A_Contracts.AContractID]='" & Me.[dbo_A_Contracts.AContractID] & "'"
End Sub

When I save the Event Procedure, it works OK, but when I try to set another button to open a different form using the same code, it wipes out the first button's click event for some reason.

I'm stumped.
 
What do you mean by wipes out?

I take it you amend the code to open a different form?

If ContractID is a Number you don't need to wrap it in "'" & ID & "'". Quotes are used for Strings.
 
I think I know what's going on.

I have 8 different forms. Each form has 8 buttons - each one launches a different form. When creating the forms, I simply copied all 8 buttons, and pasted them on each form, so no matter what form the user is on, they can easily switch between them. (I know they can click on the tabs, but the buttons look cool).

But - a particular button has the same name on all the forms, so what was happening is when I coded a procedure in 'On Click' on one of the buttons and saved the form, it was wiping out code on all the other forms, because on THIS form, those buttons weren't coded.

Duh. Each button has its own name now.

Does that make sense? So the code was working fine, I was just overwriting it with each form save, and it was driving me nuts trying to figure out what was happening.

Thanks alot for your responses, Alex.
 

Users who are viewing this thread

Back
Top Bottom