Solved

Access blank field check

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

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks capricorn. Very simple coding.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

744 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now