Please Help...Linking forms

  • Thread starter Thread starter wright305
  • Start date Start date
W

wright305

I have created a form which contains a subform. The two are linked by a field
"case number". Once you start typing in the subform, it auto fills the case
# field in the subform (works great). Now, I would like to create a button
on the form to open another (3rd) form [Witness ] and autofills the case # in
that form as well. I was told to try creating a button and for the "on click"
use the following:
DoCmd.OpenForm "Add/Update Witness",acNormal,,"[Case #] = " &
Case Number
I did this and it will open the witness form but don't autofill the case #?
Can this be done??
 
This sounds like a access database question ?? not frontpage

"If" it is an access question - - - -
When you write "stiff" into form controls that are bound to a table this
"stuff" will save to the table as soon as you leave that particular control -
there are way to stop this by the way.
If you then open another form with controls bound to the same table/query
then the form will auto fill - if not it won't

On each record you will have (well you should have anyway) a primary field
(normally an auto number formated field in the table).
You should always refer to this when refering to the record.

So if you are on formA on record withClientID 123 and you want to open formB
to ClientID 123 you would use something like this IF you have a control
called ClientID on the first form and you want to open the 2nd form at the
same ClientID -

Imprtant Note
The clientID shown in the code is the name of the form control NOT the name
of the table field to which it is bound - although these are sometime the
same ??



Private Sub SomeButtonName_Click()
On Error GoTo Err_SomeButtonName_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "The Name of the form you want to open"
stLinkCriteria = "[CDClientID]=" & Me![CDClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_SomeButtonName_Click:
Exit Sub
Err_SomeButtonName_Click:
MsgBox Err.Description
Resume Exit_SomeButtonName_Click
End Sub



For more details - ask in the access forum

Good luck
 
So in your case you could try (if you button is called "SomeButtonName" ) -
I assume that you control called "case" has a number in it and that there is
a control called "case" on each form.


Private Sub SomeButtonName_Click()
On Error GoTo Err_SomeButtonName_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Add/Update Witness"
stLinkCriteria = "[Case]=" & Me![Case]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_SomeButtonName_Click:
Exit Sub
Err_SomeButtonName_Click:
MsgBox Err.Description
Resume Exit_SomeButtonName_Click
End Sub
 
Back
Top