473,508 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I bind a form to a collection.

I wrote an access2000 database for a POS system. In it is a sales
form with a a subform showing the items being purchased. The main
form is unbound. It uses a class to hold the main form data and to
read/write to the sales table.
What I'm having trouble with is what to use as the 'Recordsource' for
the subform (Items being sold). I do not want to bind the subform
directly to the itemsSold table. What I would like to do is create a
collection of objects that are of a items class and bind the subform
to this.
Another option would be to create a recordset completely in memory (No
underlying table) and bind the subform to it. Here the issue is when
the complete sale button is pressed on the main form, how do I
reference the recordset of the subform. IE where should I create the
virtual recordset (subform, main form, module) and depending where I
create it, what is hte scope of the recordset.
Any ideas would be appreciated.
Adolph
Jan 9 '08 #1
1 3353
If you dont want to bind your textboxes you could use a recordset object
and cycle through the recordset object

Dim DB As DAO.Database, RS As DAO.RecordSet

Sub Form_Load()
Set DB = CurrentDB
Set RS = DB.OpenRecordset("Select * from tbl1 Where ID = x")

txt1 = RS!fName
txt2 = RS!lName
End Sub

Sub Current()
RS.MoveNext
txt1 = RS!fName
txt2 = RS!Lame
End Sub

Hopefully, you get the idea. But this will become a bunch of spaghetti
code. Something a little easier that does not bind your form to a table
(but sort of binds the textboxes to fields in your recordsource) would
be this:

Sub Form_Load()
Me.RecordSource = "Select * From tbl1 Where ID = x"
End Sub

In the properties of each textbox you set the controlsource just to the
name of the field in your recordSource for each field. You could also
do this with VBA, but again it starts becoming spaghetti code -
especially if you want to change the number of fields in the
recordsource.

VB.Net has greatly improved this type of functionality with the
Datagridview control (which would be a subform in Access).

Datagridview1.DataSource = dataset1.tbl1

this gives all the fields in tbl1. Then

Datagridview1.DataSource = dataset1.tbl2

this would give/show all the fields in tbl2 which is different than tbl1
but you don't have to write any spaghetti code when you change the
datasource.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jan 9 '08 #2

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

Similar topics

1
1695
by: yaniv abo | last post by:
Hello. How can I bind a list of objects to a DataGird? I have a custom collection of Customer class
2
2084
by: Pete Nelson | last post by:
Does anyone know of a way to bind a string collection to a datagrid? Basically, I have an object, CreditPlans, and a string collection, ModelNumbers. I'd like to bind the ModelNumbers collection...
2
2191
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple...
1
15021
by: Mike Hofer | last post by:
I am trying to do something a little nonstandard, and am having some difficulty determining (a) if it can be done and (b) if so, how to do it. What I want to do is fill a dropdown combobox with...
1
2929
by: Doug D via .NET 247 | last post by:
I really really need some insight on this problem I am trying to bind a strongly typed collection object to a datagrid. I already Inherited CollectionBase, but .NET says that it cannot find my...
3
3270
by: serge calderara | last post by:
Dear all, Does anyone know how to bind a System.Collection.ArraysList object to a Dataset ? Thanks for your reply Regards Serge
3
1336
by: Michael Fällgreen | last post by:
Hi, I need to make a strongly typed collection of x, and the simplets way is to inherits list(of x). With that I can bind to a list-control. However - i don't need all the methods from list(of...
12
5872
by: Monty | last post by:
Hope this is an easy one: How can I bind a text on a form to a an integer variable? Possible? Thanks!
1
1328
by: Øyvind Isaksen | last post by:
I try to make my own ArticleAttribute object and ArticleAttributeCollection, and add data to this Collection. It almost works, but the problem is that each time I add an ArticleAttribute to my...
0
7118
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
7379
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...
1
7038
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
7493
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
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5049
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
4706
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...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.