Access 2010 form with command buttons - OpenQuery and PrintPreviewQuery - ms-access

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.

Related

Access double click event to open query in listbox

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

How do I get a Dlookup result to display within another textbox on an Access database?

I have created on a database a Dlookup function to change the email address of a manager whenever the managers area is selected. It works fine but now that the control source is the Dlookup it doesn't save the results any more in the personal table.
I read up on http://p2p.wrox.com/access-vba/77907-how-save-results-dlookup-function.html a method to have a separate hidden box which displays the results from the table, which works but my trouble is now connecting the Dlookup result to the other text box.
I obviously cant control source the Dlookup result so I've instead tried to make it an before update event using the following code;
Option Compare Database
Private Sub ASMail_AfterUpdate()
ASMEmail.Value = ASMail.Value
End Sub
However this has not taken effect at all. The textbox does not change whenever I adjust the Dlookup results, and I've tried the same code in the other Change event which didn't work either.
You don't need a separate hidden textbox.
Leave the textbox control source of the manager's email linked to the personal table field and simply update the textbox value to the DLookup value when the manager area is selected.
I don't know how the manager area is selected, but as a combobox example, it would be like this:
Private Sub Combo_AfterUpdate()
Me.ASMEmail.Value = Nz(DLookup("Value", "Domain", "Criteria"), vbNullString)
End Sub

Access 2010 cascading combo boxes runtime error 424

I am getting runtime error 424 when trying to create simple cascading combo boxes.
Option Compare Database
Private Sub ModelID_Change()
SizeID.Value = Null
SizeID.Requery
End Sub
Private Sub Form_Current()
SizeID.Requery
End Sub
That is the code I'm using. any ideas?
Following on from my comment, I believe the problem isn't your code, it's that the VB editor doesn't recognise your form.
For the VB editor to recognise the form you will need invoke the Code Builder at least once.
In the deign view of your form, go to properties > events. Then you will see under the current event it will be blank.
You can click the three dots (ellipsis) and click code builder. This opens the VB editor and the sub routines will be recognised. Now when you return the properties you will see it says "Event Procedure".
I hope this helps!

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.