We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

what code do I need in a Base macro to access a field in highlighted row in a datasheet [closed]

asked 2016-10-04 13:39:39 +0200

meakasteve gravatar image

updated 2021-06-12 16:26:49 +0200

Alex Kemp gravatar image


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.


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2021-06-12 16:26:57.890903

2 Answers

Sort by » oldest newest most voted

answered 2016-10-04 22:18:21 +0200

Ratslinger gravatar image

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.


edit flag offensive delete link more


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

meakasteve gravatar imagemeakasteve ( 2016-10-08 11:07:12 +0200 )edit

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 gravatar imagemeakasteve ( 2017-08-02 14:03:40 +0200 )edit

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

Ratslinger gravatar imageRatslinger ( 2017-08-02 14:53:39 +0200 )edit

answered 2016-10-04 18:00:14 +0200

peterwt gravatar image

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

edit flag offensive delete link more


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.

meakasteve gravatar imagemeakasteve ( 2016-10-04 19:54:11 +0200 )edit

Question Tools

1 follower


Asked: 2016-10-04 13:39:39 +0200

Seen: 673 times

Last updated: Oct 04 '16