Solved

Access blank field check

Posted on 2013-01-31
3
364 Views
Last Modified: 2013-01-31
Hi all.

I have a form that allows end users to edit fields and place the original data in a historical table. The issue I'm having with the below code is that if the original data (txtVendorItemNumber_Original) is blank it will not insert the new data (txtVendorItemNumber) into the table. It works find with the original data does not match the new data in the form, but when the original data is blank then it will not update the new data. How can I get it to work when the original data is blank?

If (Me.txtVendorItemNumber_Original.Value <> Me.txtVendorItemNumber.Value) Then
    
    CurrentDb.Execute "insert into ProductSpecificationsEdit(ItemNumber,ProductSpecification,OriginalValue,UserID,ChangeDate) values ('" & Me.txtItemNumber & "','" & "VendorItemNumber" & "' ,'" & Me.txtVendorItemNumber_Original & "', '" & GetUserName() & "', '" & Now() & "')"
    CurrentDb.Execute "Update  ProductSpecifications set VendorItemNumber = '" & Me.txtVendorItemNumber & "' Where ItemNumber = '" & Me.txtItemNumber & "'"
    change_count = change_count + 1

End If

Open in new window

0
Comment
Question by:printmedia
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 38841008
try this


If (nz(Me.txtVendorItemNumber_Original.Value) <> Me.txtVendorItemNumber.Value) Then

or

If (nz(Me.txtVendorItemNumber_Original.Value) <> nz(Me.txtVendorItemNumber.Value)) Then
0
 
LVL 8

Expert Comment

by:d0ughb0y
ID: 38841015
How about this?

If (Me.txtVendorItemNumber_Original.Value <> Me.txtVendorItemNumber.Value) Then
    If Not IsNull(Me.txtVendorItemNumber_Original.Value) Then
         CurrentDb.Execute "insert into ProductSpecificationsEdit(ItemNumber,ProductSpecification,OriginalValue,UserID,ChangeDate) values ('" & Me.txtItemNumber & "','" & "VendorItemNumber" & "' ,'" & Me.txtVendorItemNumber_Original & "', '" & GetUserName() & "', '" & Now() & "')"
         CurrentDb.Execute "Update  ProductSpecifications set VendorItemNumber = '" & Me.txtVendorItemNumber & "' Where ItemNumber = '" & Me.txtItemNumber & "'"
         change_count = change_count + 1
    End If
End If

Open in new window

0
 

Author Closing Comment

by:printmedia
ID: 38841238
Thanks capricorn. Very simple coding.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question