Search Form

I

Ian

I am trying to create 2 forms that are basically linked. The first form will
be in continuous form view and will be used to scroll through part of the
available data to find what you are looking for.

On the second form I would like to be able to click on an entry in the first
form and have the new one pop-up to edit or add data to the record.

Both forms will be based on the same query but the second form will show
more fields.

Does anyone have a way to do this? I am a beginner at this sort of database
so any help would be appreciated.
 
M

Mr B

Ian,

Try the following code in the AfterUpdate event of your continuous form:

Dim lngRecID As Long

lngRecID = Me.NameOfRecordIDField
DoCmd.OpenForm "NameOfSecondForm", , , "RecordIDFieldName = " & lngRecID & ""

Just change the "NameOfRecordIDField", "NameOfSecondForm" and
"RecordIDFieldName" items to the actual values for your controls and fields.
 
I

Ian

I think this is close to what I want, but I couldn't get it to work correctly.

Whenever I have the lngRecId set as Long and try to run the event I get a
'type mismatch' error on the 'lngRecID' line. I tried changing it to As
String but then I get a pop-up box that says SSOS and requires me to enter
something in. Did I mess up the code somewhere?

Also I had to change the event to Detail_Click. The continuous form was
strictly for 'view only' purposes and I do not want anyone entering or
changing the data on this particular form.

I hope this is enough information. Thanks for your help with this.
 
M

Mr B

Ian,

As for your variable, as a last resort declare your variable as a Variant.
That should eliminate your error when reading the value from the Primary Key
field.

In the code I was assuming that you had a field in your table that was an
AutoNumber type field and would be the Primary Key for the table. That field
would produce an ID number that would be a Long type value for each new
record.

If your table does not have a AutoNumber type field then you will have to
use the value from the field that does serve as a Primary Key field.

I was also assuming that you would have a control on your continuous form
that would hold the Key value for your records and that you would use the
name of that control to read the value of the Primary Key for the current
record.

I was expecting you to use the AfterUpdate event of your form to read the
Primary Key field value. The AfterUpdate event will fire each time you
change records, even in a continuous form.

Being in Edit or Read only mode should not make any difference when reading
the information out of the current record.

Make sure you have a Key field represented by a control on your form. Then
name that control with a name using the name of the field with a prfix of
"txt" (like "txtFieldName"). This will provide you with a way to address the
specific control and it's value. You then simply pass the value retrieved
from the control for the current record to your second form.
 
I

Ian

Worked perfectly once I added the key field as a control in my forms! I did
have a primary key field but wasn't using it in the form before you suggested
it.

Thanks for all your help on this.
 
Top