Access double click event to open query in listbox - ms-access

I have a listbox in a form that displays all available queries in the database. I need to setup a double click event that when a query in the list box is selected it opens that query. In my googling all I'm finding is how to setup a double click event to open a specific record in a form. Any help would be appreciated.

You can do this on the Listbox control's DblClick event.
Private Sub YourListBoxControlName_DblClick(Cancel As Integer)
DoCmd.OpenQuery Me.YourListBoxControlName.Value
End Sub

Related

Need to Automatically Edit Access TextBox in SubForm after SetFocus

I trying to use TabControls for subforms in an Access Form.
I have a subform embedded on a page of a TabControl. I meed to move from the last data entry field in the Main Form to the first data entry field in the Subform.
When I SetFocus to the Control in the subform, it does not allow editing without clicking on the TextBox. Is there a command for immediately enabling editing?
Private Sub ReadDate_AfterUpdate()
Dim myControl As Control
Set myControl = Forms!Data_Input!BOD_Data_Subform!textBoxToEdit
myControl.SetFocus
End Sub
Thanks in advance for any suggestions.
Two steps required to select a control on a subform from a main form
Do the following in order:
Select the subform control.
Select the appropriate control on the
subform.
Example code
Private Sub ReadDate_AfterUpdate()
Dim myControl As Control
' Select the subform control first
Forms!Data_Input!BOD_Data_Subform.SetFocus
Doevents
' Select the control on the subform.
Forms!Data_Input!BOD_Data_Subform.Form!textBoxToEdit.SetFocus
End Sub
* Edits *
I suspect answer would work if there were not TabControls in Main Form. It is a two-part process but in this case the first step is:
Forms!Data_Input!subDataTabControl.Pages(0).SetFocus
Where subDataTabControl is name of the Tab Control and 0 give page index.

Access 2010 form with command buttons - OpenQuery and PrintPreviewQuery

I have created an access 2010 form where I have a listbox and two command buttons. Listbox includes all of the query names and command button one is for "query print preview" and the command button 2 is for "opening the query" which should be same as "double clicking the query name" in the listbox. So, how do I make these buttons and queries to open when double clicked in the list work?
Edit: I've updated my answer with the generic code you would need to open a query via the button or the Listbox. This assumes that the values in the Listbox are valid query names within your database.
This is easily done with a little VBA.
Option Explicit
Private Sub List_DblClick(Cancel As Integer)
Call Show_Click
End Sub
Private Sub Show_Click()
DoCmd.OpenQuery Me.List.Value
End Sub
This assumes that your listbox is called List. And your command button is called Show.
Basically, the code you want run in the button's Click event and call that sub from the list box's DblClick event.

Dynamically activate "OnClick" function in command button in a subform in access 2007

I've created a form with 3 subforms in it to display an user's details and the inventory the user has. The form enables user to update the details displayed. Thus each subform has a "save" and "undo" button. I'm trying to create a "Clear All" button on the parent form which undo all changes there are in all the 3 subforms.
I don't really want to retype the same codes used in the 3 "undo" buttons, so is there a way to make use of the Onclick function of the 3 buttons?
I've tried the following with one subform first:
Private Sub ClearAllParentForm_Click()
Me.Subform1.Form.clearButton_Click
End Sub
However, the form invokes the subform's beforeupdate event instead (a messagebox that prompts user to save the updated record). I've also tried to change the codes to Me.Subform1.Form.Undo which produces the same issue. Is there somewhere which I did wrongly or is my concept wrong?
Sorry, just started using Microsoft Access 2007 only recently so quite confused with some stuff.
You need three sub routines that are separate from the button's click event. Have each button call their respective sub routine or function. Then the one single button can call all three.
#JeffO is right, but I thought I'd expand on what he said with a little more guidance.
If you have the following in a Worksheet module:
Private Sub ClearButton_Click()
'ClearButton code here.
End Sub
You need to move the ClearButton code into a Sub in a general module. So in a new module, you need the following:
Sub clearbtn()
'ClearButton code here.
End Sub
Now, back in the Worksheet module you call this code on button click with one line:
Private Sub ClearButton_Click()
Call clearbtn
End Sub
Making these changes to your event triggers will allow you to use them elsewhere in your code. The implicit lesson here is that you can't call an event trigger sub from elsewhere in VBA, but other subs can be called from within an event trigger.

need to refresh subform based list box selection in access 2007

Preface: I have a form which has tabs. In one of the tabs, I have a list box, a button, and a sub-form. The list box is populated from two tables and has a bound column.
Needed: I need the sub-form to edit existing records of one of the tables the list box is built on and append records to the same table on button click. The sub form is to be linked to the non-bound column of the list box. Please help.. I have tried a few things in Vb but could not complete..
--Chegu.
I am not sure if I understand you correctly, but if you want to select a line in the listbox, edit the respective record in the underlying table and then save the record and update the listbox, you could work along those lines:
The listbox should not be linked, neither should the subform.
Create a procedure
Sub UpdateSubform()
subform![id]=listbox!changetableID]
End sub
In the OnLoad event of the form and in the OnChange event of the listbox call this procedure
In the afterUpdate event of the subform:
Private Sub Form_AfterUpdate()
me.parent.requery
End Sub
I didn't check this out myself, because I am away from my access - but it should work along those lines.
If thats not what you are looking for, please edit your post and at least post the information whats in the listbox and where your subform should link to.

Update problem with listbox form fed from a query

I am feeding a listbox in my form with a query result that depend on other controls of the same form. The problem is that my listbox doesn't update wheareas when I launch the query manually, the result is good.
As Remou suggests put Me.listBox.Requery in the AfterUpdate event of the control it is depending on:
Private Sub yourDataSourceUIElement_AfterUpdate()
yourListBox.Requery
End Sub