473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to add the stock quantity but that erase the total stock quantity any help!

115 100+
hi i have a form that contain 2 text box (article and qty) and a next button .
when i click on the button a new form will open in datasheet view, contain 5 text box ( size, quantity, reference, article, qty_to_add).
i want when i change the qty_to_add to modify the stock quantity (quantity in the second form).
so i wrote this :
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Add_AfterUpdate()
  2. Me.Qty.Value = Me.Qty.Value - Me.qty_to_Add.OldValue
  3. DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  4. Me.Qty.Value = Me.Qty.Value + Me.qty_to_Add.Value
  5. End Sub
and it work fine but the problem is that sometime the quantity.value is null and when i modify the qty_to_add the stock quantity became null.
Any help please...
Aug 1 '10 #1

✓ answered by missinglinq

You can use the Nz() function to change a Null to Zero.

Me.Qty.Value = Nz(Me.Qty.Value, 0) + Me.qty_to_Add.Value

Welcome to Bytes!

Linq ;0)>

4 1801
beacon
579 512MB
Hi hannoudw,

Try adding an If...Then statement that checks to see if the quantity is null before you start your other calculations.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Add_AfterUpdate()
  2.  
  3.     If Not IsNull(Me.Qty.Value) Then
  4.         Me.Qty.Value = Me.Qty.Value - Me.qty_to_Add.OldValue
  5.         DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  6.         Me.Qty.Value = Me.Qty.Value + Me.qty_to_Add.Value
  7.     Else
  8.         'Display a message to the user to enter a quantity
  9.         MsgBox "Please enter a value in the quantity field.", vbExclamation + VBOKOnly, "Null Quantity"
  10.         'Put the cursor in the Qty field so the user can enter a value
  11.         Me.Qty.SetFocus
  12.     End If
  13.  
  14. End Sub
  15.  
Aug 1 '10 #2
missinglinq
3,532 Expert 2GB
You can use the Nz() function to change a Null to Zero.

Me.Qty.Value = Nz(Me.Qty.Value, 0) + Me.qty_to_Add.Value

Welcome to Bytes!

Linq ;0)>
Aug 1 '10 #3
beacon
579 512MB
@missinglinq
Completely forgot about Nz() Linq. I was addressing it from the perspective that null values weren't acceptable, so thanks for having my back.
Aug 1 '10 #4
hannoudw
115 100+
Thanks @missinglinq
that solved the problem
now i'm trying to have a control over the total number that i added . therefore i added 2 text box on the header of the datasheet form. on of them have default value =[Forms]![Add Qty]![qtyTxt] (and that's the total quantity that i'm adding) and the other is equale of the sum of the qty_to_add (=sum[qty_to_add])
and it's not working...
olso i tried to add a button in the header and i wrote this code :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command22_Click()
  2. If Me.sum.Value <> Me.q.Value Then
  3. MsgBox ("check the adding numbers")
  4. End If
  5. End Sub
  6.  
and still not working ... any help please
Aug 2 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Parvez | last post by:
I wanna build an application that performs certian tasks 1)User Loggin through the Active directory Authentication according to the user type i need to perform the following tasks 2)I need all...
11
by: Chris | last post by:
Hi, I have MSMQ installed on my domain controller (Win 2003) and on my XP client (developer box). I created a private queue under private queues. I am able to write messages to the queue like ...
1
by: Lenn | last post by:
Hello, Is there any tool that you can point to a C# solution or project and it will generate help file (.chm) with all the classes, methods, properties, etc and their descriptions from XML...
1
by: Phil | last post by:
Hi I admit it, I am a total vb beginner. I thought I'd get hold of a copy to see if I could resolve a simple problem we have. I am looking to search AD for user objects for reporting purposes,...
2
by: sambo251 | last post by:
After running a few updates I get this very annoying "Windows Installer" error #1706 that will ne go away! It keeps saying that it cannot find the file "instantsharedevices.msi", that it is on...
8
by: tik33 | last post by:
I hope that you don't get too offended by the stupidity of my question - but I wasn't sure where else to go. Basically, I'm not a programmer but I have a website which was set up by an internet...
2
by: dbruzzese84 | last post by:
I currently have a search button that calls 2 tables and shows me the information i want. One column of info is Quanity. I want to be able to search for information and have the quanity of certain...
3
by: tonyhhisc | last post by:
This script calculates the total "listing_fee" based on the price that the user inputs into the "price" field. It works in Firefox but IE says "OBJECT NOT FOUND" please help me debug this, It's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.