473,405 Members | 2,287 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,405 software developers and data experts.

subform programming question

Using Access 2000.
Say you have a form that reads some table. Within this form you have a
subform that reads a given table of n records, but only displays say 5
of them. I want to take a certain cell from this subform and put all
those 5 cells from 5 different rows into a string. Bottom line is how
would one unite cells from a given column for a given number of rows of
that column into a single string that would display in a text field.

Thanks in advance.

Nov 13 '05 #1
8 1667
Cast your subform RecordSetClone into a recordset you can work with in
code. i.e. in an event that's fired;
Dim rs as RecordSet
Set rs = Forms!frmSubFormName.Form.RecordSetClone
Then work in the scope of the recordset you've got here instead of what
the form is showing. They're more or less the same thing, but it's a
little more staright forward to work with the recordset.
So you could loop through the recordset 5 times
Dim intX as Integer, strX as String
With rs
..MoveLast
..MoveFirst
While Not .EOF Or intx <=5
strX = strX & "," & .Fields("FieldName").Value
intX = intX + 1
.MoveNext
Wend

Nov 13 '05 #2
ge****@gmail.com wrote:
Using Access 2000.
Say you have a form that reads some table. Within this form you have a
subform that reads a given table of n records, but only displays say 5
of them. I want to take a certain cell from this subform and put all
those 5 cells from 5 different rows into a string. Bottom line is how
would one unite cells from a given column for a given number of rows of
that column into a single string that would display in a text field.

Thanks in advance.

'aircode. called form main form. pass the column name to the function
Function MakeString(strCol As String) As String
Dim rst As Recordset

'get the current set of records in the Subform
Set rst = Me("YourSubFormName").Form.RecordsetClone

If rst.RecordCount > 0 then
rst.MoveFirst
Do while Not rst.Eof
MakeString = MakeString & rst(strCol) & ", "
rst.MoveNext
Loop
'remove comma/space
MakeString = Left(MakeString,Len(MakeString)-2)

ENdif
rst.close
set rst = Nothing
End Function

Change it so the recordset points to your subform name. How it would work.

Dim strCell = MakeString("FieldName1")
and this would assign to strCell the values from FieldName1

Nov 13 '05 #3
Thank you both.

Nov 13 '05 #4
One quick question. When I tried to implement this code I keep getting
errors for either lines of code: Set rst =
Me("YourSubFormName").Form.RecordsetClone or Set rs =
Forms!frmSubFormName.Form.RecordSetClone. The first keeps saying that
it can't fine the field "YourSubFormName, but its not a field its a
recordset? The other says can't find recordset:frmSubFormName.?

Nov 13 '05 #5
ge****@gmail.com wrote:
One quick question. When I tried to implement this code I keep getting
errors for either lines of code: Set rst =
Me("YourSubFormName").Form.RecordsetClone or Set rs =
Forms!frmSubFormName.Form.RecordSetClone. The first keeps saying that
it can't fine the field "YourSubFormName, but its not a field its a
recordset? The other says can't find recordset:frmSubFormName.?


I had hoped you would substitute YourSubFormName with the subformname in
your database.

When refering to a Subform, the syntax is
'for a field
Forms!MainForm!SubForm!FieldName
'for a property
Forms!MainForm!SubForm.Form.PropertySetting

Nov 13 '05 #6
I did substitute "YourSubFormName" with my subform name. I tried using
the code in Subform.current() and mainform.current() event procedures
but nogo.

Nov 13 '05 #7
what are the object names you're working with (parent form, child form,
controls)? and in what event are you trying to execute this in? maybe
just post all the code you're using so far

Nov 13 '05 #8
Ok...I think I figured out the problem. My subform may not have
actually been a subform. It was a select statement. When you want to
insert a subform in a form you click on subform and a wizzard pops up.
You can use an existing form or choose fields from existing tables and
queries. I did the later. So in the data=>source object properties of
my subform I had a select statement. I then created a real form called
it Form1. It had the same contents as my prevous subform/select
statement. But thistime the data=>source object had "Form1". After that
the above code worked.

Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ivan | last post by:
I have a form (CustomerImfo) that has a subform within it (order). Within that subform is another subform (OrderDetail). That subform (OrderDetail) is displayed in Datasheet view. When I am...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
0
by: (Pete Cresswell) | last post by:
I've been plagued by these over the years. The text is something to the effect of "Object doesn't exist". Today I started getting the error upon opening a multi-subform form that's been...
9
by: PC Datasheet | last post by:
I'm stuck on something that seems should be easy and I need some help. My main form has an option group with five options. My subform chooses from different lists depending on which option is...
5
by: (PeteCresswell) | last post by:
Tabbed control with four subforms - one each tab. When I have everything set to "Browse" mode (i.e. all controls in all subforms locked), two of the subforms do not show on the screen. As soon...
2
by: whitc26 | last post by:
Let me preface: I'm a novice, and have no programming experience. I have created an access database and have a few tables in it. I have created a form called "clients" This form opens up and...
1
by: google | last post by:
I have a form with several subforms. Users enter the data, then on the parent there is a command button that runs code to generate a .pdf document from a report based on the data they are working...
13
by: Mary | last post by:
I'll pulling my hair out on this one and would be so appreciative of any help. I am creating a data entry form to enter results of a student survey. There are 40 questions on the survey. The...
1
by: lawton | last post by:
Source: this is an access 2003 question My knowledge level: reading books, internet, and trial & error; no formal training I'm trying to get a running sum of what's filtered in a subform which is...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.