Solved

Access blank field check

Posted on 2013-01-31
3
363 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

770 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