Solved

Access blank field check

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

932 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