473,841 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update field only if field is not null

My database has 2 tables: Table1 & Table2. If a field is not null on a
record in table2, then the not null fields in table1 that correspond to
the records in table1 needs to be updated to match the field in table2.

What I have is a form that is linked to Table2. If the users want to
change a field in the main database (table1), they fill the change in
to the form (which is linked to table2) If there is no change to the
field, they simply leave it blank and that particular field won't be
updated on the main database(table1 ). The users can change up to 30
fields listed on the form.

For example, I have a record in a Table2. Of the 30 available fields,
only 3 of them are filled in and the rest are null. So I want to be
able to update just those 3 fields in the main table (table2). This is
easy to do if it's one record. But I'm trying to automate this process
and want to be able to do this update many times for different records.
I have tried to do this using a update query that has EVERY field from
Table2 in it updating to EVERY corresponding field in Table1 based on a
criteria of some kind.

I've tried putting criteria of <>Null in the criteria of each field in
the update query. But, since there is usually one field in Table2 that
is null, none of the other fields are not null won't update.

Also, I've tried to use an IIf statment in the Field line: something
like IIf([Table2]![Field1]<>Null, [Table2]![Field1],
[Table1]![Field1]). Also, I've tried IIf(IsNull([Table2]![Field1]),
[Table2]![Field1], [Table1]![Field1]). So basically I guess my
statement above says something like, if field1 in table2 is not null,
update field1 in table1 to the value of field1 in table2, if field1 in
table2 is null, update field1 in table1 to itself. The problem here I
get is an error that says my IIf(*****) statement is not a valid name
or the text is too long.

Does all this make sense and if so do you know a way to accomplish
this? Also let me know if you need more detail.

Thanks

Jul 24 '06 #1
2 19621
I'm a bit confused. You can't update more than one record at a time,
so why not update the record on the AfterUpdate event on the form?
Store each field in a variable, and compare them to the original record
using a DLookup. Then you can use some If/Thens to update the values
if len(me.txtField 1) 1.

I'm not sure if that made sense. I know what I want to say but I'm not
sure I said it right.
Brett wrote:
My database has 2 tables: Table1 & Table2. If a field is not null on a
record in table2, then the not null fields in table1 that correspond to
the records in table1 needs to be updated to match the field in table2.

What I have is a form that is linked to Table2. If the users want to
change a field in the main database (table1), they fill the change in
to the form (which is linked to table2) If there is no change to the
field, they simply leave it blank and that particular field won't be
updated on the main database(table1 ). The users can change up to 30
fields listed on the form.

For example, I have a record in a Table2. Of the 30 available fields,
only 3 of them are filled in and the rest are null. So I want to be
able to update just those 3 fields in the main table (table2). This is
easy to do if it's one record. But I'm trying to automate this process
and want to be able to do this update many times for different records.
I have tried to do this using a update query that has EVERY field from
Table2 in it updating to EVERY corresponding field in Table1 based on a
criteria of some kind.

I've tried putting criteria of <>Null in the criteria of each field in
the update query. But, since there is usually one field in Table2 that
is null, none of the other fields are not null won't update.

Also, I've tried to use an IIf statment in the Field line: something
like IIf([Table2]![Field1]<>Null, [Table2]![Field1],
[Table1]![Field1]). Also, I've tried IIf(IsNull([Table2]![Field1]),
[Table2]![Field1], [Table1]![Field1]). So basically I guess my
statement above says something like, if field1 in table2 is not null,
update field1 in table1 to the value of field1 in table2, if field1 in
table2 is null, update field1 in table1 to itself. The problem here I
get is an error that says my IIf(*****) statement is not a valid name
or the text is too long.

Does all this make sense and if so do you know a way to accomplish
this? Also let me know if you need more detail.

Thanks
Jul 24 '06 #2
ManningFan wrote:
I'm a bit confused. You can't update more than one record at a time,
I'm not trying to update more than one record
so why not update the record on the AfterUpdate event on the form?
Maybe I can do that.....here's some more detail:

The form I created and Table2 which holds the data from the form is
more of a "holding" area. The users inputs the data onto a form. Then
at a later date, they go back to the form, select the record they
created and they "flip a swith," by moving a drop down box from No to
Yes. When the drop down box says Yes, then I can initiate the change to
the fields. I don't really want that changing to yes to trigger
anything. I'd rather maintain the control of when the data is updated
in the main table.

Here's something more specific that I need to do or could do in a macro
or vba procedure:
Check each record (in Table2) to see if the "switch" is flipped to yes,
if yes, then I check each field in the record (in Table2 still). If the
field is null, then I go to the next field. If the field is not null,
then I change the corresponding field in Table1 to the value in table2.
Then go to the next field

Does that make sense?
Store each field in a variable, and compare them to the original record
using a DLookup. Then you can use some If/Thens to update the values
if len(me.txtField 1) 1.
Based on the above detail I added would you still do what you
recommended by storing each field in a variable & such??

I was hoping to be able to do this without using vba/sql or
both.....but alas it looks like this is the thing to do..O how my
laziness is continually challenged!!!! I use vba in excel but have not
yet dove into learning vba & sql in access. I have a "beginning access
vba" by wrox publishing that I can reference and of course lots of
online documentation. But, I think I need pointed a specific direction.
I'm not sure if that made sense. I know what I want to say but I'm not
sure I said it right.
Yes that makes perfect sense
>

Brett wrote:
My database has 2 tables: Table1 & Table2. If a field is not null on a
record in table2, then the not null fields in table1 that correspond to
the records in table1 needs to be updated to match the field in table2.

What I have is a form that is linked to Table2. If the users want to
change a field in the main database (table1), they fill the change in
to the form (which is linked to table2) If there is no change to the
field, they simply leave it blank and that particular field won't be
updated on the main database(table1 ). The users can change up to 30
fields listed on the form.

For example, I have a record in a Table2. Of the 30 available fields,
only 3 of them are filled in and the rest are null. So I want to be
able to update just those 3 fields in the main table (table2). This is
easy to do if it's one record. But I'm trying to automate this process
and want to be able to do this update many times for different records.
I have tried to do this using a update query that has EVERY field from
Table2 in it updating to EVERY corresponding field in Table1 based on a
criteria of some kind.

I've tried putting criteria of <>Null in the criteria of each field in
the update query. But, since there is usually one field in Table2 that
is null, none of the other fields are not null won't update.

Also, I've tried to use an IIf statment in the Field line: something
like IIf([Table2]![Field1]<>Null, [Table2]![Field1],
[Table1]![Field1]). Also, I've tried IIf(IsNull([Table2]![Field1]),
[Table2]![Field1], [Table1]![Field1]). So basically I guess my
statement above says something like, if field1 in table2 is not null,
update field1 in table1 to the value of field1 in table2, if field1 in
table2 is null, update field1 in table1 to itself. The problem here I
get is an error that says my IIf(*****) statement is not a valid name
or the text is too long.

Does all this make sense and if so do you know a way to accomplish
this? Also let me know if you need more detail.

Thanks
Jul 25 '06 #3

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

Similar topics

0
2369
by: Steven Hilton | last post by:
I am experiencing odd behavior, and I'm hoping someone can explain why it is behaving this way, and how to get around it... When I update a row in a table with a field's data set to NULL, but the table has a NOT NULL restriction on the field, the insert still completes successfully, but transforms the NULL value to an empty string. The preferred behavior would be for mysql to emit and error and not accept the attempt to set a NULL...
9
9115
by: David Berman | last post by:
I'm having a problem with an update operation in a stored procedure. It runs so slowly that it is unusable, unless I comment a part out in which case it is very fast. However, I need the whole thing :). I have a table of email addresses of people who want to get invited to parties. Each row contains information like email address, city, state, country, and preferences for what types of events are of interest. The primary key is an...
2
2527
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an Update statement. I have a sample code to reproduce my problem. To simplify the scenario I am trying to use Order related tables to explain a little better the tables i have to work with.
3
4750
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need everything after and including the final / removed to end up with simply 8/3
3
7057
by: Bill Clark | last post by:
I have about 20,000 records pulled from Excel that I need to update. What I need to do is run an update query that bascially says: If a field is null, update it with the previous record value of that same field. In some instances, it will have to go back a few records before it finds a value that is not null. Can this be done? Thanks Bill
4
5313
by: Reney | last post by:
I have a very weird problem in updating my datagrid. Please help me to solve it. The datagrid is tied to a dataset table with five columns. Three of them are primary key and the other two columns are the ones that are of interest. These two columns have "date" type values and shows short time (i.e. 11:39). The program updates the database if I change the values in these columns, or add a new record, or delete a record. But, if one of...
11
1855
by: John | last post by:
Hi I had a working vs 2003 application with access backend. I added a couple fields in a table in access db and then to allow user to have access to these fields via app I did the following; 1. Regenerated the data adapter sqls by running the data adapter wizard and pasting the resulting code into my app. 2. Deleted the data adapter correspond to the relevant access table from the
8
1595
by: hotflash | last post by:
Hi CroCrew et All, I am working on a project that will allow user to search for their opened projects (means the CompleteDate is NULL) and be able to update their WorkDescription. Once the record (ProjectID) is created, user can search for their opened projects using either their Username or ProjectID ok without problem because the CompleteDate is NULL at this time. One thing here is when you use your Username you can only search for opened...
4
2919
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data. I have read that when there is a null value in the database that there is no record in the "dataset". Can anyone show me how to bind a value in the...
0
9706
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
10932
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...
1
10667
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,...
0
10303
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
7025
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
5692
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...
0
5881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
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
3
3140
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 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...

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.