What code do I need in a Base macro to access a field in highlighted row in a datasheet

Hi

Can someone knowledgeable in programming macros for Base help me?

I have a form (Form A) which displays data as a data-sheet. This form also
contains a button. When this button is pressed it activates a macros which
opens another form (Form B) in the databank. That bit I can do.

What I cannot do is this: I want first to highlight a row in the data-sheet
of Form A by clicking the mouse onto the blank cell at the left-hand side of
the chosen row, then when I press the button I want the macro not only to
open the Form B but also to send data held in one of the fields of the
highlighted row of Form A (the field contains primary key) to Form B.

More explicitly: The data-sheet in Form A contains a list of customers and their addresses, I select a particular customer from the data-sheet by clicking on it with the mouse. Base then highlights the row and marks it with a little green cursor (all done automatically - no macro required!) I then click on the press-button which activates the micro and this should open Form B which contains further details about the customer I marked in Form A such as what purchases he/she has made in the past. As my macro currently contains no code to pick up the data in the highlighted row, the wrong customer appears when Form B is opened.

If anyone can tell me the script that I need to do this I would be most
grateful.

meakasteve

1 Like

The attached sample has two forms. Open CUSTOMERS, select a record and press button. This will close the current form and open CUSTDATA with the same customer ID. The process consists of three simple routines. First routine is attached to the button - stores the customer ID from the selected record in the data grid in a global variable. It then calls a second routine to close the current form (easy to change if not wanted) and open another form. The third routine is called from the Open Document event of the form being opened. It creates a filter using the customer ID stored in the global variable and displays the wanted record. There are some comments within the code for clarification.

PassFormData.odb

Great !! Many many thanks. Problem Solved ! Extremely grateful Ratslinger for the time and effort you spent to help me. Meakastevie

Hi Ratslinger. If I have altered the form ‘Customers’ so that it also contains a subform grid, In this grid are listed all the customers who live in the same city as that of the selected CustID. As the customer whose CustID was selected also lives in that city his7the address is of all my friend that lived in the same city as

@meakasteve This comment is incomplete. Is this a question?

You do not need the complications of two forms and a macro.

This can be done with a single form with a sub form. The Main Form would contain your Form A and the Sub Form your Form B. The Main and Sub Forms would be linked on the ID Field.

Here is an example - SimpleSubform.odb

Thanks. That is easily the simplest and best solution. However in my case I am trying to replicate a data-bank that was written ten years ago for Access using Vista. I want to keep the same structure as the original and have the same formats in the forms and reports that are presented to the users of the data-bank. These users are volunteers and I do not want to tax their patience by confronting them with unfamiliar formats. Hence my desire to have the data transferred by a macro.