Rabu, 25 Maret 2015

Re: [MS_AccessPros] VBA code to call specific record in a form

 

Afiqah-


Using command buttons is a bad idea.  As Bill pointed out earlier, that would force you to change your form design every time you added a new model.  What you need is a combo box and a command button.  The Row Source needs to look something like:

SELECT ID, ModelName FROM tblmodelspecification ORDER BY ModelName;

You will need to use the actual name of the field in tblModelspecification that has the model name - I just guessed at "ModelName".

Set the Bound Column to 1, Column Count to 2, and Column Widths to 0";1.5"

Name the combo box cboModel.

In the Click event of the command button, run your OpenForm action.

Where Condition:  [ID] = [Forms]![frmHome]![cboModel]

You can open it in Read Only or Edit mode - your choice.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Mar 25, 2015, at 5:01 AM, afiqah afiq bubbleblue_007@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

hi John & Duanne!

let me reconstruct my question. :)

1) I have created a table tblmodelspecification, consist of 37 fields. ID is Primary field and the records stored are ( Ford Fiesta, Ford Focus, VW Polo and etc.)

2) Based on tblmodelspecification, I created a form frmmodelspecification that displays all 37 fields for one record only. By default, when I change it to form view, it will display the first record data which is Ford Fiesta.

3)I also created another form frmHome. This form is under unrelated object section. I have changed the label to button controls where I have number of buttons same as number of records. I named the button as Ford Fiesta, Ford Focus, VW Polo and etc.

4) The situation is I want the user to choose a button among buttons in frmHome. If the user click on Ford Fiesta button, the program will open frmmodelspecification and displays Ford Fiesta record.

5) my question is how to create events to fulfil the above situation?

I have tried to create an event for Ford Fiesta button. I used macro builder.
Action: OpenForm
From Name: frmmodelspecification
View: Form
Filter name:
Where Condition: [ID]=[Forms]![frmmodelspecification]![ID]
Data Mode: Edit
Window Mode: Normal

The result is when I set Data Mode to read only, the output is just a blank white screen and when I set Data Mode to Edit, the output is frmmodelspecifation form is open without any records appear. Images and labels are appeared in the form.

hmm..sorry, I'm truly a Ms Access beginner. Hope you can guide me.

Thank you!

Regards,
Afiqah






On Wednesday, March 25, 2015 3:30 AM, "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:


 
My bad.  Yes, stand-alone labels have a few events, including Click and Dbl Click.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Mar 24, 2015, at 8:22 PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

"Stand-alone" labels are the only ones that have events associated with them. Associated label controls pass the events to the parent control.
 
Duane Hookom, MVP
MS Access
 

To: MS_Access_Professionals@yahoogroups.com
From: MS_Access_Professionals@yahoogroups.com
Date: Tue, 24 Mar 2015 15:23:46 +0100
Subject: Re: [MS_AccessPros] VBA code to call specific record in a form



Duane-

Yes, that's true, but Afiqah implied these are just stand-alone labels.  And when a label is associated, clicking it fires the click event of the attached control, not the label.
 
John Viescas, Author
On Mar 24, 2015, at 2:26 PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
 
John,
I thought label controls that are not the child of another control can click, double-click, and mouse events.
 
I would try to avoid hard-coding model names as label captions on a form. This would mean having to change form designs as you add or remove models.
 
Duane Hookom, MVP
MS Access


From: MS_Access_Professionals@yahoogroups.com

Afiqah-
 
Label controls don't have any events, so I don't see how you're going to make this work.  Why not use Command Buttons and the Click event?  In the respective events, use DoCmd.OpenForm with a filter specified in the WhereCondition parameter to display the record.
John Viescas, Author
On Mar 24, 2015, at 2:34 AM, bubbleblue_007@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Hi,
I'm using Ms Access 2007.

Currently, I have designed a form (frmHome) consist of  10 labels which I named it lblFordFiesta, lblFordFocus, and etc.

I would like the user to open another form named frmmodelspecification that display Ford Fiesta record (display all fields) when the user click on lblFordFiesta and display Ford Focus record (display all fields) when the user click on lblFordFocus.

Ford Fiesta and Ford Focus records are stored in tblmodelspecification and consist of 37 fields. frmmodelspecification is created based on tblmodelspecification table while frmHome is created and categorized as unrelated objects.

Hope you can guide me to write VBA code for this event.

Thanks in advance!

Regards,
Afiqah




__._,_.___

Posted by: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (9)

.

__,_._,___

Tidak ada komentar:

Posting Komentar