Solved

Access blank field check

Posted on 2013-01-31
3
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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