Hi,
I have a form which contains a subform. Both are were creetd using the form wizard and are bound by the column IXO_NR (on two different tables), which is the control source for a textbox on both the parent and subform.
The intent was to default the subform's IXO_NR to the parent form's IXO_NR, then requery the subform to prevent the user from having to scroll through all of the subform's records to find the one they may be looking for. In the case of a new record on the parent form, IXO_NR on the subform should be reset since it contains the value from the last record selected.
I tried to reset it a number of ways and I kept getting an ODBC error as, I'm assuming, since a value was populated in the subform's textbox, Access interpreted that a new record was being added in the subform as well. Since the subform has a couple of not null columns, an ODBC error was generated.
On the parent form's FORM_CURRENT event:
If Me!txtInfoXchgO bjNr > 0 Then
Me!subfrmIXODes c!txtInfoXchgOb jNr.DefaultValu e = Me!txtInfoXchgO bjNr
Me!subfrmIXODes c.Requery
Else
' Me!subfrmIXODes c!txtInfoXchgOb jNr.Undo
' Me!subfrmIXODes c!txtInfoXchgOb jNr.Value = 0
' etc.
End If
So how can I reset the subform / subform's textbox to prevent this ?
Thanks, Ed.
13 3275
you're referencing your subform control incorrectly in this scenario. it should be
If Me!.xtInfoXchgO bjNr > 0 Then
Me.subfrmIXODes c.form.xtInfoXc hgObjNr.Default Value = Me.txtInfoXchgO bjNr
Me.subfrmIXODes c.formRequery
Else
' Me.subfrmIXODes c.form.xtInfoXc hgObjNr.Undo
' Me.subfrmIXODes c!txtInfoXchgOb jNr.Value = 0
' etc.
End If
But I'm not sure if that's going to work to solve your problem. Let us know.
J
you're referencing your subform control incorrectly in this scenario. it should be - If Me!.txtIXONr > 0 Then
-
Me.subfrmIXODesc.form.txtIXONr.DefaultValue = Me.txtIXONr
-
Me.subfrmIXODesc.formRequery
-
Else
-
' Me.subfrmIXODesc.form.txtIXONr.Undo
-
' Me.subfrmIXODesc!txtIXONr.Value = 0
-
' ????
-
End If
But I'm not sure if that's going to work to solve your problem. Let us know.
J
Hi J,
Thanks for the reply !
The code I had and the code you provided both worked as far as populating the textbox and retrieving the related records in the subform. I found that code when searching for a solution. Is you're method more efficient ?
The ODBC error is generated in the ELSE when I try to reset the textbox in the subform to a "null" value when a new record is being added and that's why it was commented out.
If I don't reset the subform's textbox when the main form is on a new record, it will be populated with an incorrect value and if data is entered on the subform and saved, it will associate the subform's data to the wrong PK.
For example, if the main form had an existing record with a PK of 2 the subform's textbox would be populated with 2 and any relevant data, if any, would be retrieved. On a new record, the main form's objects are blank but the subform's textbox contains the value of 2, instead of being blank as well.
The ODBC error occurred since the subform did not contain all of the required info for a valid insert (e.g. cannot insert a null value into columns...colum n does not allow nulls). If the required info was populated and saved, it'd be associated with the last PK value stored in the textbox, in this case 2.
So the question is, how do I reset the subform's textbox to a "null" value so Access does not try to insert a record and throw the ODBC error ?
As I'm sure you can tell, I'm not familiar with Access and it's objects, methods, etc. If you happen to have any references I could look into, please feel free to let me know.
Thanks again and all help is appreciated !
Ed.
P.S. Sorry for such a long reply :-)
Hi J,
Thanks for the reply !
The code I had and the code you provided both worked as far as populating the textbox and retrieving the related records in the subform. I found that code when searching for a solution. Is you're method more efficient ?
The ODBC error is generated in the ELSE when I try to reset the textbox in the subform to a "null" value when a new record is being added and that's why it was commented out.
If I don't reset the subform's textbox when the main form is on a new record, it will be populated with an incorrect value and if data is entered on the subform and saved, it will associate the subform's data to the wrong PK.
For example, if the main form had an existing record with a PK of 2 the subform's textbox would be populated with 2 and any relevant data, if any, would be retrieved. On a new record, the main form's objects are blank but the subform's textbox contains the value of 2, instead of being blank as well.
The ODBC error occurred since the subform did not contain all of the required info for a valid insert (e.g. cannot insert a null value into columns...colum n does not allow nulls). If the required info was populated and saved, it'd be associated with the last PK value stored in the textbox, in this case 2.
So the question is, how do I reset the subform's textbox to a "null" value so Access does not try to insert a record and throw the ODBC error ?
As I'm sure you can tell, I'm not familiar with Access and it's objects, methods, etc. If you happen to have any references I could look into, please feel free to let me know.
Thanks again and all help is appreciated !
Ed.
P.S. Sorry for such a long reply :-)
The subform record wouldn't be saved unless you actually set focus to it and enter some data. Default entries, and assumed Not Null values, even though they "appear" in the subform, aren't committed. I believe the Undo is what's causing the error..however I have no way to test that in your situation. You shouldn't have to do what you're doing.
As a test, comment out the code you have, go into your main form and enter a test record. You may see data in the subform, however...don't bother with it.
Save the Main form record.
Now go to the subform table and try to find the FK record. It will not/should not be there.
Let me know.
J
The code under the ELSE was already commented out when I posted this and remains so. When I tried the UNDO, Value = 0 or setting the textbox to a variant object that had no value, I still had the problem. This only occurs when the main form is at new record and I navigate to a previous record. My guess is when the main form record position changes, which triggers the subform's requery, Access tries to insert a row on the table linked to the subform since there is a value in the textbox.
In order for me to test this theory, I need to reset the textbox to it's initial state and value. So, is there away to do that ?
Thanks, Ed.
The code under the ELSE was already commented out when I posted this and remains so. When I tried the UNDO, Value = 0 or setting the textbox to a variant object that had no value, I still had the problem. This only occurs when the main form is at new record and I navigate to a previous record. My guess is when the main form record position changes, which triggers the subform's requery, Access tries to insert a row on the table linked to the subform since there is a value in the textbox.
In order for me to test this theory, I need to reset the textbox to it's initial state and value. So, is there away to do that ?
Thanks, Ed.
If that's the case, then don't you want to Delete that record from the table? Not just reset the text box.
There isn't any data to save initially.
The only thing that's populated on the subform, when the record changes on the main form, is the value in the textbox to pre-populate it with the main form's PK value. This ensures the new / modified data in the subform is linked properly as the FK and to make it easier for the user (not having to choose from a dropdown, etc. - they are already where they need to be). Think of it as a filter.
If there happens to be any data related to the main form's PK then the subform will display it and the user can modify or navigate as needed, but the PK value from the main form would remain in the subform. The subform's PK value should only change when the main form's record changes.
I know it's tough to diagnose a problem without an example. If there's a way I can send it to you, let me know. Just an FYI, the tables are links to a SQL Server database.....
Thanks, Ed.
There isn't any data to save initially.
The only thing that's populated on the subform, when the record changes on the main form, is the value in the textbox to pre-populate it with the main form's PK value. This ensures the new / modified data in the subform is linked properly as the FK and to make it easier for the user (not having to choose from a dropdown, etc. - they are already where they need to be). Think of it as a filter.
If there happens to be any data related to the main form's PK then the subform will display it and the user can modify or navigate as needed, but the PK value from the main form would remain in the subform. The subform's PK value should only change when the main form's record changes.
I know it's tough to diagnose a problem without an example. If there's a way I can send it to you, let me know. Just an FYI, the tables are links to a SQL Server database.....
Thanks, Ed.
Hi again Ed,
And I'm still not convinced this is an issue. The behavior that you're describing is normal behavior for related records. And again, I have to ask you...if you mark the record's PK value in your subform...then switch over to the subform's table...you'll see that the record has not been committed. It does show up on the form, but unless you put the cursor into the subform, and edit one of the fields in some way (effectively making Dirty = True)...then nothing of what you SEE on the form is saved to the tables.
I hope I'm not missing some important issue here...but try what I described to see if I'm mistaken.
J
Hi again Ed,
And I'm still not convinced this is an issue. The behavior that you're describing is normal behavior for related records. And again, I have to ask you...if you mark the record's PK value in your subform...then switch over to the subform's table...you'll see that the record has not been committed. It does show up on the form, but unless you put the cursor into the subform, and edit one of the fields in some way (effectively making Dirty = True)...then nothing of what you SEE on the form is saved to the tables.
I hope I'm not missing some important issue here...but try what I described to see if I'm mistaken.
J
Hey J,
I have no other way to describe the behavior I'm seeing and I'm sure it's normal behavior. Even if the form was stand-alone and I tried to save a record without providing the required data, the same ODBC error would occur as described.
The problem only happens when I change the value of the subform's textbox via code in the main form (see Else). -
If Me.txtIXONr > 0 Then
-
Me.subfrmIXODesc.Form.txtIXONr.DefaultValue = Me.txtIXONr
-
Me.subfrmIXODesc.Form.Requery
-
Else
-
Me.subfrmIXODesc.Form.txtIXONr.Value = 0 'I tried other methods as well
-
End If
-
Again, I'm not entering data manually. The subform's textbox is populated with the PK value from the main form via code to try and remove any existing value which was populated from the prior record.
So my choices seem to be to try and figure out how to reset a textbox so it contains no value and prevents the ODBC error or have the user use a dropdown and not try to reset the textbox at all. My preference is the former.
How do I reset a textbox ?
Thanks, Ed.
Hey J,
I have no other way to describe the behavior I'm seeing and I'm sure it's normal behavior. Even if the form was stand-alone and I tried to save a record without providing the required data, the same ODBC error would occur as described.
The problem only happens when I change the value of the subform's textbox via code in the main form (see Else). -
If Me.txtIXONr > 0 Then
-
Me.subfrmIXODesc.Form.txtIXONr.DefaultValue = Me.txtIXONr
-
Me.subfrmIXODesc.Form.Requery
-
Else
-
Me.subfrmIXODesc.Form.txtIXONr.Value = 0 'I tried other methods as well
-
End If
-
Again, I'm not entering data manually. The subform's textbox is populated with the PK value from the main form via code to try and remove any existing value which was populated from the prior record.
So my choices seem to be to try and figure out how to reset a textbox so it contains no value and prevents the ODBC error or have the user use a dropdown and not try to reset the textbox at all. My preference is the former.
How do I reset a textbox ?
Thanks, Ed.
Ed,
I still think something simple is missing to cause you to have to go to all this effort.
When you placed your subform onto the main form...you linked the master/child fields right?
This is a very high level view of a proper table layout..can you confirm that you have a set-up like this?
MainTable
ID (autonumber)
Details
Details
Etc..
SubTable
ID(Autonumber)
MainTableID (Numeric Foreign Key)
Details
Details
Etc..
And you're linkiing using the Main Table ID and the Sub Table MainTableID
is that correct?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andante.in.Blue |
last post by:
Hi everyone! In Access 97, I have a parent form and a subform that
are both based on the same query. The main form is continuous and
serves up a summary for each record. The subform provides details on
the record and is linked to the parent record via an autonumber ID.
My users want to be able to add new records to the table underlying
the main query (the query is structured so that new records can be
added via its database view). I...
|
by: Ray |
last post by:
I have a main form with a subform. The main form has a combo box which
lists all the clients which in turn are displayed in the subform.
The subform is bound to the combo box and all work well. however, I
would like to be able to add a new client in the subform but this is,
of course bound to the combo box. Can anyone tell me if there is a way
to enter a new client in the subform with out receiving an error
message?
TIA - Ray
|
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 data in each record, which
includes the ID of the father and the mother (who also have records in the
table). One record per form.
I have a Tab Control in the form, and in one of the tabs I have a subform
(sfmSiblings) in which I wish to list...
|
by: Robert |
last post by:
Need some help to stop me going around in circles on this one....
Have a nested subform (subform2) which simulates a continuous form for the
record on the parent subform.
Subform2 has rows of either an option button plus two text fields or a
checkbox plus two text fields
Am wanting to save the user entries into an underlying table. Tag property
for each option button, check box or text field has the value of the key
|
by: Robert |
last post by:
I have a form with two subforms on it. both subs have the same
controlsource. Subform1 is a continuous form that acts as an index. The
second subform is a single record that the user will use to edit the record.
There is a button (transparent) over the record on subform1 that when
clicked should force the second subform to goto that record. Any thoughts on
how to go about this?
Thanks Robert
| |
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 with. If a
user enters data in a subform, then directly clicks the command button
on the parent form, the data in the subform is not included in their
document. I THOUGHT that as soon as focus left the subform, any
pending changes to the data...
|
by: MLH |
last post by:
I have a form, frmVehicleEntryForm.
On it is a subform control named frmAddnlOwnrListSubForm.
The subform control's source object is frmAddnlOwnrListSubForm.
When I click on the subform control, an attempt to SAVE the partially
entered record on the main form is attempted. I do not understand
where this behavior is coming from or why. Haven't a clue where to
look. Anyone familiar with this behaviour?
Here's my subform control's Enter...
|
by: pzh20 |
last post by:
I have an unbound form/subform where I populate a combo box on the main form, and using the onchange event, display fields from a table in a datasheet subform.
I want to add a new record via the subform, allowing the user to type certain fields but complete other fields via code in the beforeinsert event as follows
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.Kitchen = Me.Parent.Kitchen(2)
Me.lookupRoute = Me.Parent.Kitchen(1)
...
|
by: troy_lee |
last post by:
I have a table (Table A). It has one field, a PK. It is in a 1:M with
another table (Table B). I am having trouble with a form/subform setup
to view the 1:M records.
On the parent form, there is a combo box with a Select query to select
one of the records in Table A. (The parent form is bound to Table A.)
I want to be able to first, view all of the corresponding records from
Table B and then second, give an option for editing these...
|
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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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: 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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |