Select a Customer from ListBox???? in different Forms

  • Thread starter malik via AccessMonster.com
  • Start date
M

malik via AccessMonster.com

Hi
I have a form Name "FrmDrVoucher" and a SubForm "FrmDrVoucherBodySubForm" In
this form. I have "AccountNo" Txtbox Control in SUbForm. After this control I
have a small button by pressing it a new form appears with a list box having
all my customers Id's and names....

I wanted that by double clicking on a customer name in list box, It fill up
the
AccountNo in my SubForm with selected CustomerId from Listbox.

For This I used the Following Code in ListBox Dbl Click Event (in newly PopUp
Form)

Private Sub List0_DblClick(Cancel As Integer)

[Forms]![FrmDrVoucher]![FrmDrVoucherBodySubform].[Form].[AccountNo] = Me.
List0
Me.Close

End Sub

No I want to use the same form for many forms as
FrmCrVoucher
FrmSales
FrmJVoucher
etc...

Plz tell me that how can I use the Only One Form (withListBox) to select
Parties for several forms.

Thank You
 
T

Tom Wickerath

Hi Malik,
Plz tell me that how can I use the Only One Form (withListBox) to select
Parties for several forms.

So you have the functionality working correctly for one case, right?
Assuming your answer is "Yes", one method that I think would work would be to
use the optional OpenArgs parameter, when opening the form with the list box.
Pass the name of the calling form as the OpenArg.

Then, you can set up a Select Case statement in the DblClick procedure, but
perhaps you should give this control a more reasonable name first, instead of
just "List0". Something like this:

Private Sub List0_DblClick(Cancel As Integer)

Select Case Me.OpenArgs
Case "FrmDrVoucher"
[Forms]![FrmDrVoucher]![FrmDrVoucherBodySubform].[Form].[AccountNo]
= Me.List0
Case "FrmCrVoucher"
[Forms]![FrmCrVoucher]![FrmCrVoucherBodySubform].[Form].[AccountNo]
= Me.List0
Case "FrmSales"
[Forms]![FrmSales]![FrmFrmSalesBodySubform].[Form].[AccountNo] =
Me.List0
Case "FrmJVoucher"

[Forms]![FrmJVoucher]![FrmFrmJVoucherBodySubform].[Form].[AccountNo] =
Me.List0
Case Else 'To handle an unexpected result
Msgbox "Unexpected Form Name. Please contact DBA for assistance.", _
vbCritical, "Error in lboCustomers Double-Click in
form FormName"
End Select



Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

malik via AccessMonster.com said:
Hi
I have a form Name "FrmDrVoucher" and a SubForm "FrmDrVoucherBodySubForm" In
this form. I have "AccountNo" Txtbox Control in SUbForm. After this control I
have a small button by pressing it a new form appears with a list box having
all my customers Id's and names....

I wanted that by double clicking on a customer name in list box, It fill up
the
AccountNo in my SubForm with selected CustomerId from Listbox.

For This I used the Following Code in ListBox Dbl Click Event (in newly PopUp
Form)

Private Sub List0_DblClick(Cancel As Integer)

[Forms]![FrmDrVoucher]![FrmDrVoucherBodySubform].[Form].[AccountNo] = Me.
List0
Me.Close

End Sub

No I want to use the same form for many forms as
FrmCrVoucher
FrmSales
FrmJVoucher
etc...

Plz tell me that how can I use the Only One Form (withListBox) to select
Parties for several forms.

Thank You
 
T

Tom Wickerath

That should probably be:
DoCmd.Close acForm, Me.Name

to help gaurd against unexpected results, which could conceivably happen if
some other form happened to get focus at the wrong instant.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 
M

malik via AccessMonster.com

Thanks for the response Tom
But the code u told me is not working , It just Executes the Case Else msgbox.


Thanks.


Tom said:
Hi Malik,
Plz tell me that how can I use the Only One Form (withListBox) to select
Parties for several forms.

So you have the functionality working correctly for one case, right?
Assuming your answer is "Yes", one method that I think would work would be to
use the optional OpenArgs parameter, when opening the form with the list box.
Pass the name of the calling form as the OpenArg.

Then, you can set up a Select Case statement in the DblClick procedure, but
perhaps you should give this control a more reasonable name first, instead of
just "List0". Something like this:

Private Sub List0_DblClick(Cancel As Integer)

Select Case Me.OpenArgs
Case "FrmDrVoucher"
[Forms]![FrmDrVoucher]![FrmDrVoucherBodySubform].[Form].[AccountNo]
= Me.List0
Case "FrmCrVoucher"
[Forms]![FrmCrVoucher]![FrmCrVoucherBodySubform].[Form].[AccountNo]
= Me.List0
Case "FrmSales"
[Forms]![FrmSales]![FrmFrmSalesBodySubform].[Form].[AccountNo] =
Me.List0
Case "FrmJVoucher"

[Forms]![FrmJVoucher]![FrmFrmJVoucherBodySubform].[Form].[AccountNo] =
Me.List0
Case Else 'To handle an unexpected result
Msgbox "Unexpected Form Name. Please contact DBA for assistance.", _
vbCritical, "Error in lboCustomers Double-Click in
form FormName"
End Select

Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
Hi
I have a form Name "FrmDrVoucher" and a SubForm "FrmDrVoucherBodySubForm" In
[quoted text clipped - 27 lines]
Thank You
 
T

Tom Wickerath

You haven't given me a lot to go on, as far as trying to help you. I don't
have a copy of your database, so I can only help with suggestions based on
clues you can provide.

Add a Debug.Print statement:

Private Sub List0_DblClick(Cancel As Integer)
Debug.Print "OpenArgs: " & Me.OpenArgs

Select Case Me.OpenArgs
:
:
:
End Select


Run the code a few times. Then open the Immediate Window (<Ctrl><G>). What
values, if any, were printed to the Immediate Window? Note: If you only see
something like this:

OpenArgs:

Then this indicates that the OpenArgs argument was null. Perhaps you did not
use this optional parameter correctly, in the DoCmd.OpenForm statements?


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 
M

malik via AccessMonster.com

Yeah bro it shows only

OpenArgs:

Now plz tell me that waht arguments should I use for this form in Docmd.
OpenForm statement???

Thank u.
 
T

Tom Wickerath

Hi Malik,

The fact that you are only seeing "OpenArgs:" means that the OpenArgs is
null, in other words, you are not correctly passing an OpenArgs argument.
Show your line of code that includes:

DoCmd.OpenForm ..........

for opening the form that you want to be able to use as a common form for
four other forms.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 

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