473,412 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Call Value from SubForm with On Click Event

28
Good Morning Pro's,

My first time trying to loop through a Subform to grab a value. I would like to call the ID value in the row I click. My first time trying this as I usually use the Listboxes click event to call a value. is this possible on a subform? to click a row and call it's ID value already present in the row?

What I have thusfar but it only loops through all the rows and returns all values for ID. Anyway to grab the ID for just the row the user has clicked?

Expand|Select|Wrap|Line Numbers
  1. Dim MyValue As String
  2. Dim rs As Recordset
  3.  
  4. Set rs = Forms![ProjectForm]!Plan_Update.Form.RecordsetClone
  5.  
  6. If Not rs.EOF Then rs.MoveFirst
  7. While Not rs.EOF
  8.     MyValue = rs!ID
  9.         MsgBox MyValue
  10.     rs.MoveNext
  11. Wend
  12.  

Thanks,
Paul

The subform is datasheet view.
Sep 8 '14 #1

✓ answered by jforbes

I’m not 100% sure what you are attempting to do, but my understanding is that you are attempting to find the ID of the Selected Record of a Subform from your Main Form (ProjectForm). If so, you can get the value from the Subform like this:
Expand|Select|Wrap|Line Numbers
  1. Dim MyValue As String
  2. MyValue = Me.Plan_Update.Form!ID
  3.  
This assumes that the Control for your Subform is named Plan_Update.

I've also seen this helpful reference posted here and there on this forum that helps with situations like this one:
http://access.mvps.org/access/forms/frm0031.htm

5 8173
jforbes
1,107 Expert 1GB
I’m not 100% sure what you are attempting to do, but my understanding is that you are attempting to find the ID of the Selected Record of a Subform from your Main Form (ProjectForm). If so, you can get the value from the Subform like this:
Expand|Select|Wrap|Line Numbers
  1. Dim MyValue As String
  2. MyValue = Me.Plan_Update.Form!ID
  3.  
This assumes that the Control for your Subform is named Plan_Update.

I've also seen this helpful reference posted here and there on this forum that helps with situations like this one:
http://access.mvps.org/access/forms/frm0031.htm
Sep 8 '14 #2
pwag
28
Hi and Thanks jforbes. What I'm trying to do is mimic the behavior of a list box. When you click on a listbox it gives you the idea value based on the bound column OR Listbox.column(0). I'm trying to get the ID value. Thanks.
Sep 8 '14 #3
zmbd
5,501 Expert Mod 4TB
Well depending on how you have things setup with the forms there can be twists on the following:

Usually, there is a Main_Form (most often in single form view) and a sub_form (most often in data table view) linked by the common field in the parent-child relationship. Despite the appearance, the subform is not a list_box control. It may contain such controls; however, it is not in and of itself a list box.

Now when the user clicks on the record, that becomes the bound form's current record. This holds true in the subform.
Once selected, there are a lot of methods to refer to this current record's field(s) value(s); however, I find the easiest is to refer to the bound control by name of the control and then the value property of that control.

For example: Main_Form and the SubForm_1

On SubForm_1 you have a record source and one of your controls is called "Example_Value" bound to a field in the recordsource

From within the SubForm_1 you can use the Me.ExampleValue.Value format to refer to the value of the field for the currently selected record in VBA associated with the subform or other controls on the subform. No need to provide the entire path. Keep in mind the SCOPE of form makes the "Me" shortcut refers to the subform at this point.

From the Main_Form you would need Me!SubForm_1!ExampleValue.Value (mind you the scope is the main_form here... thus the "me" in this case is the Main_form.)

Reference Sheet for Referring to Controls on Forms
Sep 8 '14 #4
twinnyfo
3,653 Expert Mod 2GB
Paul,

With J above, I, too, am a bit confused as to what you are trying to do. In the code you posted, all you are really doing is looping through the records and assigning the value of ID to your variable. But since you are looping through all records, you are not really doing anything.

J's method above will work, but must be couched in some event that will execute it.

You mention the form is in datasheet view, which limits your possibilities to either an OnFocus or Before/After Update event. And these events would need to be coded for each visible field.

What is it that you want to do with your ID that you have identified? It may be easier to use a continuous form, displaying your desired fields, and include a Command Button to execute your code. It is sometimes a more straightforward approach. However, there may also be reasons for you maintaining the datasheet view--which is also understandable.
Sep 8 '14 #5
pwag
28
Thanks jforbes. that seems to have worked. i took out the loop and it works like i want it to now.

This is what worked.
Expand|Select|Wrap|Line Numbers
  1. Dim MyValue As String
  2. MyValue = Nz(Forms![Project]!Plan_T_Update.Form.ID, 0)
  3. MsgBox MyValue
Sep 8 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: cwm137 | last post by:
I am trying to call the click event of a button located in a subform called "Order Subform" from a button in the parent. However, since the subform was made with the wizard, it contains a space in...
2
by: Uninvisible | last post by:
I have put together a db for a law firm to keep track of counterfeit activities. There are four parent tables: tblContact tblTransaction tblAction tblFile I have created a form,...
2
by: Tamir Khason | last post by:
I build user control, consists of different things (e.g label, image, etc.) I want to handle click (and other) events, however I can not do it until I do not assign event handler for each control...
20
by: anthonymelillo | last post by:
Is there a way to call a button click event from somewhere else ? I have a text box where I would like to call a button click event when a user presses enter in the text box. Can I do this ?...
1
by: hazz | last post by:
oh it hurts to be a newbie again....:-( I have a button click event I want to handle for a button to create an excel spreadsheet from gridview contents. I can't write the code for the button...
1
by: pradheepayyanar | last post by:
hey all i have a list of <TR> with values like username, area, region, etc... my requirement is that on clicking any of the rows, i need to popup an alert saying this username is clicked. how to...
1
by: adrianm4380 | last post by:
Is it possible to call the on click event procedure for a command button on a custom toolbar? I have a menu of buttons that open various forms in varying ways that are all controlled in the on...
4
by: Claire | last post by:
Is it possible to call a controls click event if it has one attached? In a previous language I'd use something similar to if (sender.OnClick != null)(button(sender).OnClick(sender,e)); thank...
4
by: Savita23 | last post by:
Hi, I have a subform in datasheet layout embedded in the main form.I want to invoke a procedure on the double click of each record in the subform.Is there a away by which I can fire the double...
2
by: Fuzz13 | last post by:
Within a method I want based on an if then statement to trigger a button click but I don't know how. Is there a way to call a button click event?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.