Double Click Event on List Box

YNWA

Registered User.
Local time
Today, 21:21
Joined
Jun 2, 2009
Messages
905
Hi,

I currently have a search form that runs a query to filter results when typing into a search field.

When I find the record I want, I can double click and it opens a form based on the ID of the result to the ID form record.

I use this code:

Code:
'Private Sub SearchResults_DblClick(Cancel As Integer)
'If CurrentProject.AllForms("tbl_InvoiceDueDates subform").IsLoaded Then
'     DoCmd.Close acForm, "tbl_InvoiceDueDates subform"
'End If
' DoCmd.OpenForm "tbl_InvoiceDueDates subform", acNormal, , "[InvoiceDueID] = " & Me.SearchResults.Column(0)

'End Sub

Is it possible to say open form tbl_InvoiceDueDates subform but when it opens instead of opening the main Client form, to get it to open on say TabCtlInvoices?

So it opens the clients form but pre loaded onto the Invoices tab?

Cheers
 
Use the OpenArgs argument of the OpenForm method. You can pass the tab/Page Name/Number you want to open OR a simple boolean value 0/1. In the Forms Open Event check the OpenArgs value and open as required.

Eg
If Me.OpenArgs & "" = "" then exit sub
Me.SubFormName.TabControl=Me>openArgs
End If

OR

If Me.OpenArgs = TRUE then
Show tab required
End If
 
Last edited:
Do I need to specify the tab or can it work by me searching, finding the record, then double click and it open that record on the tab that the form wants?

Eg. my invoices form opens clients form. but I want it to open clients form on the invoice tab?

Do I scrap my previous code or?
 
You only need add the OpenArgs argument to the OpenForm code you already use, EG

DoCmd.OpenForm "tbl_InvoiceDueDates subform", acNormal, , "[InvoiceDueID] = " & Me.SearchResults.Column,,,OpenArgsHere

So this code will open tbl_InvoiceDueDates subform in Normal view where InvoiceDueID] = " & Me.SearchResults.Column and pass an argument via OpenArgs
 
Thanks.

Do i need to apply a Form_Load event detailing similar to :

Private Sub Form_Load()

' If Not IsNull(Me.OpenArgs) Then
' If form's OpenArgs property has a value, assign the contents
' of OpenArgs to the strPlayerName field. OpenArgs will contain
' a Player name if this form is opened using the OpenForm
' method with an OpenArgs argument, as done in the sfrmHomePlayers
' and sfrmAwayPlayers sub form's Home/Away PlayerID_NotInList
' event procedure. Also sets the new player team name to
' value in main Fixtures form
Dim strPlayer As String
Dim lngTeam As Long

If Not IsNull(Me.OpenArgs) Then
' Split OpenArgs data into separate fields
strPlayer = Left(OpenArgs, InStr(OpenArgs, ";") - 1)
lngTeam = Mid(OpenArgs, InStr(OpenArgs, ";") + 1)

Me![strPlayerName] = strPlayer
Me.lngTeamID = lngTeam

End If
End Sub
 
You would use this code in the Open event. Use of the semicolon (or another symbol) and Split() to pass multiple arguments is very good.
 
Sorry mate.

I am totally lost. I have applied ,,,OpenArgs to the end of my DoCmd.OpenForm.

I have a form called Clients, with subform Invoices. The control in InvoicesCtl

I am opening the form based on the ClientID. I can get the client form open at correct client but just cant get it to open that tab first?

Coding isn't my strong poitn I am afraid.
 
EG of OpenArgs

When opening the form i want to make a the 2nd tab visible. DoCmd.OpenForm "FormName", acNormal, , ,,,2
In the forms Open Event i use; Me.FormName.TabControl=Me.OpenArgs

OR
i want to make a the tab "ThisOne" visible. DoCmd.OpenForm "FormName", acNormal, , ,,,"ThisOne"
In the forms Open Event i use; Me.FormName.TabControl=Me.OpenArgs

What value are you passing via OpenArgs?
 
EG of OpenArgs

When opening the form i want to make a the 2nd tab visible. DoCmd.OpenForm "FormName", acNormal, , ,,,2
In the forms Open Event i use; Me.FormName.TabControl=Me.OpenArgs

OR
i want to make a the tab "ThisOne" visible. DoCmd.OpenForm "FormName", acNormal, , ,,,"ThisOne"
In the forms Open Event i use; Me.FormName.TabControl=Me.OpenArgs

What value are you passing via OpenArgs?

Nothing. I just stuck it at the end then got confused with the next bit.

So in the Search Form Open Event? Is it the search form I put this in? I use Me.frm_Clients.InvoicesTab=Me.OpenArgs
 
Do I put

Private Sub Form_Open(Cancel As Integer)
Me.frm_Clients.InvoicesTb = Me.OpenArgs
End Sub

On the clients form?

or?
 
You would need to put the code in the Open event of the main form, not the subforms. Then address the subforms tabcontrol. Use this syntax for a tabcontrol on a subform;

Me.SubformName.Form.TabcontrolName
 
Ok. My subform doesn't contain tabs. The main form frm_Clients has the tabs and tab InvoiceTb contains a subform.
 
oOk, so in frm_Clients Open event use

Me.TabControlName.Pages(Me.OpenArgs).SetFocus

TabContolName is the name of the Tab Control object (holder) NOT a name of a tabcontrol page.

So your code should look something like this;

In the search forms SearchResults_DblClick event use;
DoCmd.OpenForm "tbl_InvoiceDueDates subform", acNormal, , "[InvoiceDueID] = " & Me.SearchResults.Column,,,” InvoiceTb”


In the frm_Clients Open Event use;
Me.TabControlName.Pages(Me.OpenArgs).SetFocus

This will open your tbl_InvoiceDueDates subform form and set focus on the InvoiceTb tab.

If this does not resolve your problem, I must be missing something so please attach your DB.
 
Last edited:
oOk, so in frm_Clients Open event use

Me.TabControlName.Pages(Me.OpenArgs).SetFocus

TabContolName is the name of the Tab Control object (holder) NOT a name of a tabcontrol page.

So your code should look something like this;

In the search forms SearchResults_DblClick event use;
DoCmd.OpenForm "tbl_InvoiceDueDates subform", acNormal, , "[InvoiceDueID] = " & Me.SearchResults.Column,,,” InvoiceTb”


In the frm_Clients Open Event use;
Me.TabControlName.Pages(Me.OpenArgs).SetFocus

This will open your tbl_InvoiceDueDates subform form and set focus on the InvoiceTb tab.

If this does not resolve your problem, I must be missing something so please attach your DB.

Thanks I will try at home. So I mist change the tbl_InvoiceDueDate subform with frm_Clients as this is the form I want to open, but then go to InvoiceTb.
 

Users who are viewing this thread

Back
Top Bottom