Open secondary form and copy keyfield

Real Wally

Registered User.
Local time
Today, 22:59
Joined
Jan 28, 2003
Messages
107
Hi,

I've struggling wity this issue for some time now.
What I have is a form with key field SearchID (autonumber) and a button that opens a secondary form with notes attached to the record on the first form. The 2 forms are linked by the SearchID number. This works without a problem when the frmNotes_short actually has a value in the SearchID field. However, a problem occurs when I open a secondary field for the first time, the SearchID field has the default value 0. I know it's not a huge effort to manually add the ID# but it would be so much nicer if that number gets copied automatically from the first form (frmSearches). I've gone through many postings that address similar issues but cannot get it to work. Here's the code I curently use:

Button on the frmSearch:

Private Sub shortnotes_Click()
DoCmd.OpenForm "frmSearches",,,,,,Me!
SearchID
End Sub

On open event for secondary form:

If Not IsNull(Me.OpenArgs) Then
SearchID.SetFocus
SearchID= Me.OpenArgs
Call SearchID_AfterUpdate
End If

Can anyone tell me what it is I'm doing wrong please?

Wally
 
Private Sub shortnotes_Click()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "frmSearches",,,,,,Me!
SearchID
 
Thanks for helping Rich.

Unfortunately I get an error message again:

'Compile error. Invalid use of property'.

On the code screen that opens next, the first line of your code is higlighted in yellow and the last line is blue.

Do you mind having another look?

Thanks,

Wally
 
Wally

I overcame the same problem by creating a second form (using the same query as the main form (frmSearches). ) and inserting the secondary form (frmNotes_short) as a subform. The ID (SearchID) for the main from being the link.

I included some fields (file number, name of organisation) with identifying information in the second form as a safeguard that I was attaching the notes in the subform to the right record. Works fine.

HTH

Allan
 
Rich said:
DoCmd.OpenForm "frmSearches",,,,,,Me!
SearchID

Did you read that as two separate lines? It should be one.

Code:
DoCmd.OpenForm "frmSearches",,,,,,Me!SearchID
 
Problem solved

Thanks again for your appreciated advice.


Mile, I did indeed have 2 line where there should be one. With the one line it still didn't work, frmSearches was opening itself instead of the frmNotes_short. Stupid mistake from my side.

On open event for secondary form I now have:

If Not IsNull(Me.OpenArgs) Then
SearchID.SetFocus
SearchID= Me.OpenArgs
Call SearchID_AfterUpdate

Works great now. Thanks for your help.

Alex, your suggestion a is very usefull idea for another DB I'm setting up. It's not the direction I'd like to go with this form though.
 

Users who are viewing this thread

Back
Top Bottom