473,394 Members | 1,965 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,394 software developers and data experts.

Updating a Field Value From a Dialog

I am very new to Access. I have created a database in Access 2003. I
can enter the required record fields from a form. I would like to add
a feature that allows a user to update the "quantity" field (it is type
long integer). The update would be to add or subtract a user-entered
number to/from the current quantity. Perhaps a dialog would pop up on
entry to the quantity field. The user would enter a number and press
"Add" or "Subtract" to perform the desired action. Unfortunately, I
don't yet know how to make this happen.

As it is now, the user can change the quantity field but would have to
calculate the new value if he/she wanted to add or subtract to/from the
current quantity.

Thanks for any quidance you can give me on this.

Charles

Mar 31 '06 #1
2 1563
Charles,

I would suggest that you could add code to the On Enter of the Quantity
field that would ask the user for the change in the quantity. But, if
you do that, I would lock the quantity so it could not be changed in
any other way.

So, to lock the quantity field, bring up the properties and on the Data
tab, click Locked and check Yes.

Then give the Quantity field a name - like lngQuantity - the name is
found on the Other tab of the Properties.

On the Events tab, find On Enter and click in the white field. Click on
the three dots and select Code Editor.

Add between the Private Sub and End Sub on blank lines:

On Error Resume Next

Dim lngQty As Long
dim strAnswer as String

'As a note, the following should all be one line
strAnswer = InputBox("What do you want to increment the quantity by? If
you want to lower the quantity, put a minus in front of the number.)"

lngQty = val(strAnswer)

if lngQty <> 0 then

'The next line is also one line
me.cboQuantity.value = me.cboQuantity.value + lngQty

End If

_____________________END OF CODE

This tells the computer if there is a problem just keep going.

Sets up two variables to hold the answer given and convert it to a
number.

Then, if the number is anything other than zero it is added to the
existing number.

Be sure to notice where I have left you notes for lines that should not
wrap.

Mar 31 '06 #2

Susan K wrote:
Charles,

I would suggest that you could add code to the On Enter of the Quantity
field that would ask the user for the change in the quantity. But, if
you do that, I would lock the quantity so it could not be changed in
any other way.

So, to lock the quantity field, bring up the properties and on the Data
tab, click Locked and check Yes.

Then give the Quantity field a name - like lngQuantity - the name is
found on the Other tab of the Properties.

On the Events tab, find On Enter and click in the white field. Click on
the three dots and select Code Editor.

Add between the Private Sub and End Sub on blank lines:

On Error Resume Next

Dim lngQty As Long
dim strAnswer as String

'As a note, the following should all be one line
strAnswer = InputBox("What do you want to increment the quantity by? If
you want to lower the quantity, put a minus in front of the number.)"

lngQty = val(strAnswer)

if lngQty <> 0 then

'The next line is also one line
me.cboQuantity.value = me.cboQuantity.value + lngQty

End If

_____________________END OF CODE

This tells the computer if there is a problem just keep going.

Sets up two variables to hold the answer given and convert it to a
number.

Then, if the number is anything other than zero it is added to the
existing number.

Be sure to notice where I have left you notes for lines that should not
wrap.


Susan,

Thanks so much for your help. I'll give your suggestion a try.

Charles

Apr 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
5
by: Ryan Ternier | last post by:
I'm having an issue with an SQL insert statement. It's a very simple statement, and it's causing too much fuss. strSQL = "INSERT INTO tblFieldLayouts(TypeID, FieldID, OrderID, Hidden) VALUES("...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
4
by: Macbane | last post by:
Hi, I have a 'main' form called frmIssues which has a subform control (named linkIssuesDrug) containing the subform sfrmLink_Issues_Drugs. A control button on the main form opens a pop-up form...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
11
by: xelA | last post by:
Thanks, it worked. Another problem: Hey folks, where is the bug in this code? When updating the date field, it is updating all the records in the table with the same value (e.g. 2008-01-07) instead...
0
by: Mike | last post by:
So here's the situation (.NET 2.0 btw): I have a form, and on this form is a textbox among many other databound controls. The textbox is bound to a field in a data table via the Text property. ...
1
by: cerilocke | last post by:
I have a repeater in which I have a hidden field (input type = hidden), a textbox (asp:TextBox), a checkbox (input type = checkbox) and a label (asp:Label). I have bound all four items to the same...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.