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

How to Update record from message box

Microblitz
Hi All,

I started messing about with VBA yesterday (I'm a newbie at this language) and have run across a problem which i hope you can help me with.

I'm writing a little stock control program in clicking a command button opens a message box which asks for a number of items to add to the currently displayed record in the main form (called Parts).

You's think this would be simple and i have some code which i have cobbled together which I would work if I could keep the record from zipping back to record 1 everytime I save to the "current_Stock" field.

The main form has previous/next record buttons and a fairly standard "search by dropdown box" which all seems to be working.

So what I'm working toward is ;

Select record by search or prev/next button
Click Command button to add inventory stock
Enter value in message box
Value is added to current record/current_stock field
messagebox closes revealing updated record.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command83_Click()
  2. On Error GoTo Err_Command83_Click
  3.  
  4.     Dim intTemp As Integer
  5.     Dim Vtemp As Integer
  6.     Dim Resultant As Integer
  7.  
  8.     Vtemp = CurrentDb.OpenRecordset("SELECT * FROM Part")(12)
  9.     intTemp = InputBox("Sub Current Stock", "Add Stock", 0) 
  10.     Me.Current_Stock = intTemp + Vtemp
  11.  
  12. Exit_Command83_Click:
  13.     Me.Requery
  14.     Exit Sub
  15. Err_Command83_Click:
  16. MsgBox "Chris has officially cocked up!" & vbCrLf & vbCrLf & "With the Error No: " & Err.Number & vbCrLf & Err.Description
  17.     Resume Exit_Command83_Click
  18.  
Jul 2 '10 #1

✓ answered by gershwyn

I'm not sure why you're going back to a previous record, but I would change a few things about your code. Your main form is bound to "Parts", right? Then you should be able to add to the current_stock field directly, without mucking about with recordsets (which I suspect is somehow related to your problem.)
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command83_Click()
  2. On Error GoTo Err_Command83_Click
  3.  
  4.     Dim strTemp As String
  5.     strTemp = InputBox("Sub Current Stock", "Add Stock", 0) 
  6.     If IsNumeric(strTemp) Then
  7.       Me!Current_Stock = Me!Current_Stock + Int(strTemp)
  8.     Else
  9.       MsgBox "Please enter a numeric value."
  10.     End If
  11.  
  12. Exit_Command83_Click:
  13.     Me.Requery
  14.     Exit Sub
  15. Err_Command83_Click:
  16. MsgBox "Chris has officially cocked up!" & vbCrLf & vbCrLf & "With the Error No: " & Err.Number & vbCrLf & Err.Description
  17.     Resume Exit_Command83_Click
  18.  
  19. End Sub
  20.  
I changed the return value from inputBox to a string, so text input will be handled without raising an error.

Expand|Select|Wrap|Line Numbers
  1. MsgBox "Chris has officially cocked up!"
As I am also a Chris, I may start adding to this my error handling routines. Though it does raise the question, which is worse - an official or an unofficial cock up?

5 2950
gershwyn
122 100+
I'm not sure why you're going back to a previous record, but I would change a few things about your code. Your main form is bound to "Parts", right? Then you should be able to add to the current_stock field directly, without mucking about with recordsets (which I suspect is somehow related to your problem.)
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command83_Click()
  2. On Error GoTo Err_Command83_Click
  3.  
  4.     Dim strTemp As String
  5.     strTemp = InputBox("Sub Current Stock", "Add Stock", 0) 
  6.     If IsNumeric(strTemp) Then
  7.       Me!Current_Stock = Me!Current_Stock + Int(strTemp)
  8.     Else
  9.       MsgBox "Please enter a numeric value."
  10.     End If
  11.  
  12. Exit_Command83_Click:
  13.     Me.Requery
  14.     Exit Sub
  15. Err_Command83_Click:
  16. MsgBox "Chris has officially cocked up!" & vbCrLf & vbCrLf & "With the Error No: " & Err.Number & vbCrLf & Err.Description
  17.     Resume Exit_Command83_Click
  18.  
  19. End Sub
  20.  
I changed the return value from inputBox to a string, so text input will be handled without raising an error.

Expand|Select|Wrap|Line Numbers
  1. MsgBox "Chris has officially cocked up!"
As I am also a Chris, I may start adding to this my error handling routines. Though it does raise the question, which is worse - an official or an unofficial cock up?
Jul 2 '10 #2
NeoPa
32,556 Expert Mod 16PB
I'm struggling to work out what you're saying your problem is, so I'll just offer a snippet of advice. Generally, rather than requiring an InputBox call, you could design the form with an unbound TextBox (or ComboBox in some circumstances) control where the operator could enter their value. This has various benefits, including the continued visibility of the value as well as much better control of it (You can specify the sort of data to accept etc). You can even hide it at certain times if that is important, so that it only shows when you feel it's appropriate.

Welcome to Bytes!
Jul 2 '10 #3
@gershwyn
I have reverted the official to unofficial error:)

Took a look at your code and it works but the record jumps back to record one in the database as soon as that message box is closed. There must be somthing else causing the issue.

I'm just reverting back to an earlier evrsion to see if its somthing that I added in my search to clear the fault.
Jul 2 '10 #4
FishVal
2,653 Expert 2GB
@Microblitz
Expand|Select|Wrap|Line Numbers
  1. Me.Requery
points form to a first record after loading recordset. It is not a bug, it is a feature.
If you need to just save a current record you could use one of the following:
Expand|Select|Wrap|Line Numbers
  1. Me.Dirty = False
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdSaveRecord
Jul 2 '10 #5
ADezii
8,834 Expert 8TB
If you insist on maintaining this approach, then you should provide some form of minimal Validation on the Value entered in the Input Box, as in:
Expand|Select|Wrap|Line Numbers
  1. Dim strTemp As String
  2. Dim Vtemp As Integer
  3. Dim Resultant As Integer
  4.  
  5. strTemp = InputBox$("Sub Current Stock", "Add Stock", 0)
  6.  
  7. If strTemp = "" Or Not IsNumeric(strTemp) Or strTemp = "0" Then
  8.   Exit Sub
  9. End If
  10.  
  11. 'If you get here, you have a legitimate, Numeric Value >= 1
  12. Me.Current_Stock = Val(strTemp) + Vtemp
  13.  'continue...
Jul 3 '10 #6

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

Similar topics

1
by: oldandgrey | last post by:
I'm looking at producing an application that will allow multiple users to order multiple items/ parts from what would effectively be an online store. These users could be ordering several hundred...
1
by: toedipper | last post by:
Hello, PHP4 and MySql I have the code below, a mixture of handcoded and Dreamweaver genaratd php code. Basically it's an update record form - I load the values from a db and bind text boxes...
4
by: James P. | last post by:
Hello there, I have a bound-form using Navigator so that the user can move back and forth to update record in the form. Every time a record was modified and the user clicks the Navigator to...
2
by: Tinius | last post by:
I am trying to update a field of type IMAGE. I am able to do this by deleting the record and then INSERTing a new record as shown below in the commented section. But I really want to do this...
1
by: Daniel | last post by:
Does someone know how to update record in ASP.NET ? Because i face a problem after updating the record in SQLServer database. The problem is : I do update to a record's field called DateIn. After...
2
by: Agnes | last post by:
Binding Manager (update problem) by agnescheng I use binding Manager to bind the textbox, I got a problem on update record. E.g Me.txtUserId.Text = "PETER" bm.current.item("userid") =...
1
by: ashish ranjan | last post by:
Hi there , I m in great need to know: How to select row from grid and update record in database using Ajax. u can use c#,.net and java script. Thanks in advance, Ashish Ranjan
12
ranjana1980
by: ranjana1980 | last post by:
How to update record of two tables when in Table A RegNo is primary key and in Table B RegNo is foreign Key and i like to update where A.RegNo=B.RegNo
1
Kosal
by: Kosal | last post by:
Dear Sir/Madam I would like to Update record to last record in database that unkown last record please advice. thanks Best Regard
1
by: dreamy | last post by:
i have 2 tables, 1. account -id, -accounttypeid, -name 2. accounttype -accounttypeid, -type.
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.