473,588 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binding mainform and subforms to SQL-server-view

6 New Member
In Access 2007 I have a main form with several subforms. All forms are unbound, and the recordsets for the forms are set during the OnOpen-event in the main-form.

I use ADO and OleDB to connect to the SQL-server and to bind the recordsets with the forms.

Everything works OK when the forms open the first time.

In the main form I have a combo that resets the recordsets for all the forms depending on the selected value. When I do this, the recordset in the main form changes ok, but all the subforms are getting closed, so it's impossible to set their recordset-property. The subforms are not linked to the main form.

I have spent a couple of days trying to solve this, I'll post some of my code if that can help.

Regards
Jon Ole
Oct 27 '08 #1
14 4032
NeoPa
32,566 Recognized Expert Moderator MVP
I'd be interested in seeing the code that sets the Record Sources for the subforms. In the AfterUpdate event of the ComboBox I expect.
Oct 27 '08 #2
JonOle
6 New Member
I'd be interested in seeing the code that sets the Record Sources for the subforms. In the AfterUpdate event of the ComboBox I expect.
I've placed the code on the click-event in the combo:
Expand|Select|Wrap|Line Numbers
  1. Private Sub PersonLst_Click()
  2. GjeldendePersonID = Me.ActiveControl
  3. SettSkjemaFamPersRstEr
  4. End Sub
GjeldendePerson ID is the global variable that holds the primary key. SettSkjemaFamPe rsRstEr is placed in a module and goes on like this:
Expand|Select|Wrap|Line Numbers
  1. Public Sub SettSkjemaFamPersRstEr()
  2. SettFamilierPersonerRst
  3. SettTreningsdetaljerRst
  4. SettFamilieRst
  5. SettAdresseRst
  6. SettEpostRst
  7. SettTransRst
  8. SettOrdreRst
  9. SettDugnadRst
  10. End Sub
SettFamilierPer sonerRst replaces the recordset of the main form:
Expand|Select|Wrap|Line Numbers
  1. Public Sub SettFamilierPersonerRst()
  2. Dim FormRst As New ADODB.Recordset
  3. Dim SQLstr As String
  4. Dim Conn As ADODB.Connection
  5. Set Conn = New ADODB.Connection
  6. With Conn
  7.     .Provider = "Microsoft.Access.OLEDB.10.0"
  8.     .Properties("Data Provider") = "SQLOLEDB"
  9.     .Properties("Initial Catalog") = "kunstlop"
  10.     .Properties("Data Source") = "myserver\SQLEXPRESS"
  11.     .Properties("User ID") = "UID"
  12.     .Properties("Password") = "pwd"
  13.     .Open
  14. End With
  15. If Nz(GjeldendePersonID, 0) = 0 Then
  16.     SQLstr = "Select TOP 1 * from vw_Form_PersonerFamilie "
  17. 'This is used when the form opens the first time.
  18. Else
  19. 'This is used when the sub is called from the combo
  20.     SQLstr = "Select * from vw_Form_PersonerFamilie where personid= " & GjeldendePersonID
  21. End If
  22. FormRst.Open SQLstr, Conn, adOpenKeyset, adLockOptimistic
  23. Set Forms!PersonerFamilie.Recordset = FormRst
  24. Set FormRst = Nothing
  25. Set Conn = Nothing
  26. End Sub
SettTreningsdet aljerRst replaces the recordset on the first subform:
Expand|Select|Wrap|Line Numbers
  1. Public Sub SettTreningsdetaljerRst()
  2. Dim Conn As ADODB.Connection
  3. Set Conn = New ADODB.Connection
  4. With Conn
  5.     .Provider = "Microsoft.Access.OLEDB.10.0"
  6.     .Properties("Data Provider") = "SQLOLEDB"
  7.     .Properties("Initial Catalog") = "kunstlop"
  8.     .Properties("Data Source") = "myserver\SQLEXPRESS"
  9.     .Properties("User ID") = "UID"
  10.     .Properties("Password") = "pwd"
  11.     .Open
  12. End With
  13. Dim TreningsTidRst As New ADODB.Recordset
  14. TreningsTidRst.Open "Select * from qTreningLopereGjeldende where personid= " & GjeldendePersonID, Conn, adOpenKeyset, adLockOptimistic
  15. If Not TreningsTidRst.EOF Then Set Forms!PersonerFamilie.sTreningstider.Form.Recordset = TreningsTidRst
  16. Set TreningsTidRst = Nothing
  17. Set Conn = Nothing
  18. End Sub
(The conn-settings will of course be placed in a global function if I got this to work)

The remaining Sett*-statements takes care of the other subforms in the same way.

I would really appreciate some help with this :-)
Oct 28 '08 #3
NeoPa
32,566 Recognized Expert Moderator MVP
I'm not ignoring this. I just had lots to keep me busy today.

I hope to get on to it later, but if you see nothing more before tomorrow please feel free to **Bump** it.
Oct 28 '08 #4
NeoPa
32,566 Recognized Expert Moderator MVP
The first thing I notice is that the event you're using is not correct. You are assuming the ComboBox will only ever be set by the mouse. Also that all clicks will change the value. This is not reliable and the AfterUpdate event should be used instead.

I doubt that is your fundamental problem though.

It seems to me that in the most part you are making this a little more complicated than necessary. Specifying a different (generally filtered) record source every time instead of setting the record source once, and simply changing the filter whenever a new value is selected.

Does this make sense?

Can we proceed on these lines?
Oct 29 '08 #5
JonOle
6 New Member
The first thing I notice is that the event you're using is not correct. You are assuming the ComboBox will only ever be set by the mouse. Also that all clicks will change the value. This is not reliable and the AfterUpdate event should be used instead.

I doubt that is your fundamental problem though.

It seems to me that in the most part you are making this a little more complicated than necessary. Specifying a different (generally filtered) record source every time instead of setting the record source once, and simply changing the filter whenever a new value is selected.

Does this make sense?

Can we proceed on these lines?
Yes, this makes absolutely sense to me, and I agree that this is too complicated. I suppose it has been like this because I use the tools that I knows - a rather common habit, I think.

My goal is to gain acceptable speed in communication with my sql-server when connecting via vpn. It would have been very easy to use ODBC-linked tables, but I don't want to wait 5 minutes for the form to refresh... Therefore I want to gather only the information from the sql-server I need. The recordsource should also be updateable (I know the recordset in my code isn't, but they will be with the uniquetable-property).

Can you lead my on a better way? I have thought of pt-queries or sending parameters to stored procedures, but I haven't had time to experiment with this. And I was probably locked in my own stubbornness about wanting the revordset-method to work :-)
Oct 29 '08 #6
NeoPa
32,566 Recognized Expert Moderator MVP
I don't see any problem with using the recordset method (except we may have to be creative about restricting the number of records when it is first opened).

Otherwise, I would simply change the .FilterBy & .FilterOn properties when the selection is changed. I can help with that if you need it, but I don't think you're likely to need much help with this. It's a lot simpler than what you're already doing.

I'm afraid that, though I understand some of the concepts you're using here, I have very little experience with making connections in code. Obviously I will help as much as I can if you need it, but that side of things is not a strong point for me.

Let me know if that helps or you want further explanation / help.
Oct 29 '08 #7
NeoPa
32,566 Recognized Expert Moderator MVP
I should mention also, that where before you used "TOP 1" in your original record source, this will not be used when filtering. Instead, apply a filter of, possibly, an empty string. Subsequent uses will set a filter to match the selected value, but first time you clearly don't want too much delay for data. Filtering to an empty list should minimise that in a similar way to using "TOP 1".
Oct 29 '08 #8
JonOle
6 New Member
I don't see any problem with using the recordset method (except we may have to be creative about restricting the number of records when it is first opened).

Otherwise, I would simply change the .FilterBy & .FilterOn properties when the selection is changed. I can help with that if you need it, but I don't think you're likely to need much help with this. It's a lot simpler than what you're already doing.

I'm afraid that, though I understand some of the concepts you're using here, I have very little experience with making connections in code. Obviously I will help as much as I can if you need it, but that side of things is not a strong point for me.

Let me know if that helps or you want further explanation / help.
I don't think the connection is the problem here, but it can be something there that triggers Access to close the subforms when I reset the recordset in the mainform. But I would like to hear your suggestions - I think you have knowledge that could help me further on.

If I use filtering in the form, I would have to bind the form to the entire recordset, wouldn't I? Meaning that the whole table will be transferred from the sql-server to the client where Access frontend is, every time the query is refreshed? And again: This will take time and network resources?

If it is so: That's why I wanted to filter the data on the sql-server-side, and they will be - with creating a new recordset everytime I need new data in the forms.

But - I just don't understand why these subforms are closing when they not are connected with the mainform. So: If i cannot solve this, it might be a solution to use pass-through-queries as a recordsource. Then I can replace the query with a new one each time I need to update the data. Just want be less complicated, though ... :-)
Oct 29 '08 #9
NeoPa
32,566 Recognized Expert Moderator MVP
...
If I use filtering in the form, I would have to bind the form to the entire recordset, wouldn't I? Meaning that the whole table will be transferred from the sql-server to the client where Access frontend is, every time the query is refreshed? And again: This will take time and network resources?
...
I don't think it would mean that if the filter is set at the start. However, you can only be sure if you test it.

My experience (not with SQL Server back end mind) is that applying a filter is passed back intelligently to the source (thereby stopping tranference of unrequired data). Check it out and see what you find in your case.
Oct 29 '08 #10

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

Similar topics

1
7458
by: JJMM | last post by:
Hi, I have a form (form1) with a large number of subforms inside it (around 20 subforms), There is the possibility of filtering the data using a pop-up form that create/change a query (all the subforms are linked to that query), Once that I create/change the query (using the pop-up form), Is there any easy way to update all the 20 subforms inside form1?. Normally I use to change the recordsource in each subform to show the
1
2693
by: William Bradley | last post by:
At the moment I am having a problem with relationships and updating tables. The following is a production run. Table1 -- MainFormTable1 -- Basic Table Record Table2 ----SubFormTable2 -- Components of the Production Table3 ----SubFormTable3 -- QC Of the Production Table4 ----SubFormTable4 -- Customers to whom the production is sent. The MainFormTable1 has the three subforms contained within it. I am having
0
1915
by: Dalan | last post by:
I'm sure there is a workaround for this, but haven't found it yet. I have a mainform with two subforms and after one or both of the subforms are updated, then clicking the Refresh button on the mainform (to show updated values), causes the updated subform(s) to automatically scroll up to one blank line if a new record was entered, or to the line that was edited. All of the prior subform records are not viewable or accessible until exiting...
5
3364
by: Bob | last post by:
Hi Everybody I have a form called frmListBox that is connected to a table tblListBox. This is opened from a form called "frmInvoiceOrder" which has a subform called "zfrmInvoiceOrder" and floats above (ie is pop-up) ! Private Sub ListBox_DblClick(Cancel As Integer) DoCmd.OpenForm "Forms!!!.Form! = Me!ListBox.Column(1) Forms!!.Form! = Me!ListBox.Column(2)
4
1674
by: Wout | last post by:
Hello there, i have a main form to define products in. i have a subform1 to fill in the related materials i have a subform2 to fill in the machines to process the materials subform1 is related to mainform through "ProductId", subform2 is related to subform1 through "MaterialId" both subforms are displayed on the mainform. i need to find out how i can copy a product-record including all
1
5455
by: tizmagik | last post by:
I have a Starting form ("frmStart") and a main form ("frmCustomer") inside frmCustomer are two subform, one with it's own subform. So frmCustomer has two subforms ("sbfArtist" and "sbfAddress") inside subform "sbfArtist" is another subform, "sbfTitle"... I'll try to create a visible heiarchy: frmStart ----frmCustomer --------sbfAddress --------sbfArtist
3
1867
by: RookieDan | last post by:
MS ACC 2003, WS. In the subform i have query showing the results according to this SQL. It shows (grouped) number of customer data belonging to a specific dealer/vendor has in a related table. Used tables: Dealer/Vendor table is called SE_DealerList Customer table is called CustomerData This SQL shows the result, between 2 dates (DateField0 and DateField2):
5
3905
by: jedraw | last post by:
I am trying to use the information provided in Allen Brownes response see Response. I have a mainform, a tabctl with 5 pages , 5 subforms and 1 subfrom control. I placed the subformname in the page tag for each of the pages. (That should load the proper subform when the tabctl is clicked). Now I'm trying to synchronize the subforms with the mainform and am having difficulty. The subform control is not bound. The mainform contains...
7
2141
by: JohnHo | last post by:
I have been working with Access for a little while but have never used mainforms/subforms before. Here is my problem/scenario: I have a main form (frmMain) with a few other forms for data data entry (frmOne, frmTwo, ...). I have the same table (tblCallLog) as the record source for each of these forms. I have used the MainForm and SubForm with the Parent/child linking fields (lngCaseID). I would like to have the data entry in a seires...
64
6762
by: lovelydan | last post by:
hi all i need someone to help me with a code that will enable me filter records in a subform form through a combo box attached to a mainform-that has a main menu that controls all the sub form that runs under sourceObject on the mainform unbound frame. like, when i a company name on mainform combo box then the subform shows only records for that company. eg like how it works when filtering a query.. regards. lovelydan P.S. subforms...
0
7929
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7862
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8228
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8357
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8223
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6634
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5729
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3847
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.