Pass value between forms

M

Mr. Smith

Hi.
I think this is simple, but still I cant figure out the best way.

I have a main_form which opens as default form in my Access application. The
key element in the form is a combo box listing clients (cboClients). The
user selects a client from the list, and all values in the form updates
based on the selected client.

Also I have a second form which shows our top 20 clients in a listbox
(cboTop20).

What I want:
When the user doubble click on a top 20 client, I want the client id to be
passed on to the main_form, and the main_form to be updated based on the
cboTop20 id.

In my "perfect" VBA world this would work (consider it as pseudo code):

Private sub cboTop20_onDoubble_Click()
main_form.Form.load(cboTop20)
End Sub

Private sub main_form load(i as integer)
If i not vbNothing then
cboClients = i
main_form .requery
end if
End sub

I do hope some of you understands my issue and can give me a hint or a
resource where I can dig this out.

Regards
Mr. Smith
 
N

Nikos Yannacopoulos

You only need one procedure:

Private Sub cboTop20_DblClick(Cancel As Integer)
Forms!main_form.cboClients = Me.cboTop20
Forms!main_form.Requery
End Sub

assuming (a) both cboClients and cboTop20 have the same field as bound
column, presumably ClientID or something like that (the Clients table
PK), and (b) the main form is already open. If the latter is not the
case, then add this line:

DoCmd.OpenForm "main_form"

as the very first line in the above procedure.


HTH,
Nikos
 
M

Mr. Smith

Thanks Nikos.
I'm nearly there.

Thing is, I have a Public Sub cboClients_After_Update() which I need to run
after the value has been copied from cboTop20 to cboClients. I try to call
it through this statement:
Forms!main_form.Form.cboClients_After_Update
but it fail.

Trying to find out why (posted a new request in this news group also)

Thanks again
Mr. Smith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top