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
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.
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: - Private Sub PersonLst_Click()
-
GjeldendePersonID = Me.ActiveControl
-
SettSkjemaFamPersRstEr
-
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: - Public Sub SettSkjemaFamPersRstEr()
-
SettFamilierPersonerRst
-
SettTreningsdetaljerRst
-
SettFamilieRst
-
SettAdresseRst
-
SettEpostRst
-
SettTransRst
-
SettOrdreRst
-
SettDugnadRst
-
End Sub
SettFamilierPer sonerRst replaces the recordset of the main form: - Public Sub SettFamilierPersonerRst()
-
Dim FormRst As New ADODB.Recordset
-
Dim SQLstr As String
-
Dim Conn As ADODB.Connection
-
Set Conn = New ADODB.Connection
-
With Conn
-
.Provider = "Microsoft.Access.OLEDB.10.0"
-
.Properties("Data Provider") = "SQLOLEDB"
-
.Properties("Initial Catalog") = "kunstlop"
-
.Properties("Data Source") = "myserver\SQLEXPRESS"
-
.Properties("User ID") = "UID"
-
.Properties("Password") = "pwd"
-
.Open
-
End With
-
If Nz(GjeldendePersonID, 0) = 0 Then
-
SQLstr = "Select TOP 1 * from vw_Form_PersonerFamilie "
-
'This is used when the form opens the first time.
-
Else
-
'This is used when the sub is called from the combo
-
SQLstr = "Select * from vw_Form_PersonerFamilie where personid= " & GjeldendePersonID
-
End If
-
FormRst.Open SQLstr, Conn, adOpenKeyset, adLockOptimistic
-
Set Forms!PersonerFamilie.Recordset = FormRst
-
Set FormRst = Nothing
-
Set Conn = Nothing
-
End Sub
SettTreningsdet aljerRst replaces the recordset on the first subform: - Public Sub SettTreningsdetaljerRst()
-
Dim Conn As ADODB.Connection
-
Set Conn = New ADODB.Connection
-
With Conn
-
.Provider = "Microsoft.Access.OLEDB.10.0"
-
.Properties("Data Provider") = "SQLOLEDB"
-
.Properties("Initial Catalog") = "kunstlop"
-
.Properties("Data Source") = "myserver\SQLEXPRESS"
-
.Properties("User ID") = "UID"
-
.Properties("Password") = "pwd"
-
.Open
-
End With
-
Dim TreningsTidRst As New ADODB.Recordset
-
TreningsTidRst.Open "Select * from qTreningLopereGjeldende where personid= " & GjeldendePersonID, Conn, adOpenKeyset, adLockOptimistic
-
If Not TreningsTidRst.EOF Then Set Forms!PersonerFamilie.sTreningstider.Form.Recordset = TreningsTidRst
-
Set TreningsTidRst = Nothing
-
Set Conn = Nothing
-
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 :-)
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.
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?
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 :-)
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.
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".
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 ... :-)
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
|
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...
|
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)
|
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
| |
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
|
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):
|
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...
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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();...
|
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...
| |