473,549 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Spin button refresh

Abhean
32 New Member
Working on a form in access for medical inventory system. This form I want to allow the user to use up and down arrows (spinbutton) to modify the "OnHand" quantity.

The spin button works fine. I placed a refresh in SpinButton_Upda ted so that the user could see the qty being changed. However, if the user simply wishes to change the amount by hand from the text box I have a Runtime '2115' that is thrown saying that a macro or function set to the BeforeUpdate or Validation rule property is preventing access from saving data. The error is thrown at the refresh command.

Expand|Select|Wrap|Line Numbers
  1. Private Sub BtnClearRocheQR_Click()
  2.     'set searchbar to blank
  3.     Me.comboSearchRocheQR = Null
  4.     'Put focus back on searchbar
  5.     Me.comboSearchRocheQR.SetFocus
  6. End Sub
  7.  
  8. Private Sub SpinButton8_Updated(Code As Integer)
  9.     'refresh the page so user can see the change
  10.     Refresh
  11. End Sub
  12.  
Is there something else I need to be using to use instead of the spinbutton or code modification to take care of this error?
Apr 24 '19 #1
10 2601
twinnyfo
3,653 Recognized Expert Moderator Specialist
The best way to manage this is to use error handling to negate that error--since there is nothing that is really causing anything to break if you accept the value entered manually:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SpinButton8_Updated(Code As Integer)
  2. On Error GoTo EH
  3.     'refresh the page so user can see the change
  4.     Call Me.Refresh
  5. EH:
  6.     If Err.Number = 2115 Then Resume Next
  7. End Sub
I also added the "Me." prefix to your call to Refresh. It is always better to be more explicit, so that the DB knows exactly what it is you are Refreshing.

However, I cannot explain "why" the controls behave this way.

Hope this hepps!
Apr 24 '19 #2
Abhean
32 New Member
Sweet! Thank you so much Twinnyfo (once again) for your awesome help.
Apr 24 '19 #3
ADezii
8,834 Recognized Expert Expert
You should also check and see if the Value entered into the Text Box is not NULL, is Numeric, and is within the acceptable Range (MIN <==> MAX) of the Spin Button Control. To accomplish all that and actually write the Value back to the Spin Button Control, I created a simple Demo for. Obviously, it makes assumptions about Control Names and the Code exists in the AfterUpdate() Event of the Text Box.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSpinDemo_AfterUpdate()
  2. Dim txt As Access.TextBox
  3.  
  4. Set txt = Me![txtSpinDemo]
  5.  
  6. 'Make sure Field is NOT NULL and is Numeric
  7. If IsNull(txt) Or Not IsNumeric(CStr(txt)) Then
  8.     Exit Sub
  9. Else
  10.   'Is Value entered into Text Box is not within the MIN and MAX Limits
  11.   'of the Spin Button, then notify User
  12.   If Val(txt.Value) < Me![SpinButton4].Min Or Val(txt.Value) > Me![SpinButton4].Max Then
  13.     MsgBox "The Range of Values should be between " & Me![SpinButton4].Min & " and " & _
  14.             Me![SpinButton4].Max & "!", vbExclamation, "Invalid Entry"
  15.     txt.Value = Null
  16.   Else
  17.     'If you get here, all is OK so write Value back to Spin Button
  18.     Me![SpinButton4].Value = Me![txtSpinDemo].Value
  19.   End If
  20. End If
  21. End Sub
Apr 24 '19 #4
Abhean
32 New Member
while we are on spin buttons. Is there a setting between the "up arrow" and the "down Arrow"?

Meaning, if I wanted to assign a value to a field if they click the up arrow, but another value when down arrow was clicked.

Edited:
Found the answer
spinup and spindown function.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Spinbutton8_spindown()
  2.     'set usagedate
  3.     MsgBox "Changes saved?"
  4. End Sub
  5.  
  6. Private Sub Spinbutton8_spinup()
  7.     'set usagedate
  8.     MsgBox "Changes saved?"
  9. End Sub
  10.  
Happy happy, thanks!
Apr 24 '19 #5
ADezii
8,834 Recognized Expert Expert
The Spin Button Control has two Events that will allow you to execute two different actions depending on which Button was clicked. I am referring to the SpinUp() and SpinDown() Events. An example follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub SpinButton1_SpinUp()
  2.   MsgBox "Spin Up"
  3. End Sub
  4.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub SpinButton1_SpinDown()
  2.   MsgBox "Spin Down"
  3. End Sub
Apr 24 '19 #6
twinnyfo
3,653 Recognized Expert Moderator Specialist
Also, to add more discussion to this issue....

Thisis only a guess, but I surmise that you have both the SpinButton Control and the TextBox Control bound to the same field in the underlying record source? In such cases, you may be asking for the described problem.

A "more better" way to design it is to have one or the other bound to the underlying record source, but not both. Then, whenever you update one, you update the other through VBA beneath the form. This "may" alleviate the problem altogether, since you are not conflicting the table with trying to write to teh same field with two different controls.

Just a hunch--I haven't tested this. None of my applications use incremental adjustments to data like this.

Just more fodder for thought.
Apr 24 '19 #7
ADezii
8,834 Recognized Expert Expert
but I surmise that you have both the SpinButton Control and the TextBox Control bound to the same field in the underlying record source?
I don't think that both Controls can be Bound at the same time (have the same Control Source).
Apr 24 '19 #8
twinnyfo
3,653 Recognized Expert Moderator Specialist
ADezii,

You got me into experimentation mode!

Yes, it is possible to have two different controls bound to the same underlying field--which is how I duplicated OP's error in the first place.

However, I would recommend the following as a proposed new best answer, as it eliminates the need for Error Trapping and works within the requirements of the different controls.

First, either the text box or the spin button (but not both) should be bound to the underlying field. The other control should be unbound.

Then, your code is as simple as the following:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Form_Current()
  5.     Me.Spinbutton8 = Me.txtTextBox
  6.     'This assumes text box is bound
  7.     'Vice versa if spin button is bound
  8. End Sub
  9.  
  10. Private Sub Spinbutton8_Updated(Code As Integer)
  11.     Me.txtValue = Me.Spinbutton8
  12. End Sub
  13.  
  14. Private Sub txtTextBox_AfterUpdate()
  15.     Me.Spinbutton8 = Me.txtTextBox
  16. End Sub
As you can see, we are simply applying the new value of the updated control to the other control whenever either is updated. A whole lot more less clumsier than the previous solution.
Apr 25 '19 #9
NeoPa
32,564 Recognized Expert Moderator MVP
Always happy to oblige Twinny - But enough with the tautology!!
Apr 25 '19 #10

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

Similar topics

2
6899
by: Mark | last post by:
I have autorepeat turned on for a command button that increments the value in a textbox. When I click on the button and hold the mouse button down, the value in the textbox does not change. When I release the mouse button, the value in the textbox changes to where it incremented depending on the length of time I held the mouse button down. How...
3
10015
by: Sameer | last post by:
I have a webpage that has a link button. This link button on click opens up a new page. This is what is happening: 1. Load the web page. 2. Click on the link. 3. Refresh the web-page. Result: The webpage gets refreshed and the link buttons onClick event is fired.
2
9567
by: Kapil Jain | last post by:
Dear All, I would like to disable back and forward button + Refresh button. Please help in doing this. I want this because i am displaying data from mysql database and on back and forward button complete logic get failed. Also i would like disable save as option + copy & select all option. Please urgently help me.
3
2845
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I have VS 2005 (C#) There is a control numericUpDown so you can spin numeric values. What I need to do is to spin date (+- one day). How to do that? Moreover, I want a user to type the date as well. So the control should validate the typed values on the fly. Is it possible?
0
1157
by: devour | last post by:
i am using glade+pygtk+python ,what i wanna do is get a float type number from user, make some mathematical operations using python then output the result using glade. i tried text entry but i found it only accepts strings so i used spin button and it worked but the problem is it takes &displays only integers though i used get value () & set...
0
11816
acoder
by: acoder | last post by:
Problem onload and onunload events do not fire when going back, forward or refreshing the page Browser Opera Example Any code using onload or onunload, e.g. window.onload = init; where init() is a function which initialises some variables (for example).
7
5117
by: Janusz Dacxzko | last post by:
Excel 2000 (9.0.2720) vb-6. We have a column of Cells and the SpinButton. Let say for this example: column 1 row 1 cell have value "A" column 1 row 2 cell have value "B" column 1 row 3 cell have value "C" Cell with value "A" is is highlited (has focus) Now we press "SpinButton" down. We exchange values "A" and "B" so we have B - row 1 ...
2
1305
by: cssalas83 | last post by:
Im preparing in an excel sheet a purchase order form and im just new with the VBA and right now im just learning how make it in excel. Im currently stocked with the problem that I do not know how I can have a continuous number – to have a +1 prior to the last Order number. I have at cellK10 the cell for the order number, when the refresh button...
1
3490
by: sakthi23 | last post by:
Hi, I'm using sql server database and Visual Studio 2010. I have a form with DataGridView. After making the changes in the data, it is saved in the database. The data gets saved in the database, but the modified data does not get displayed in the DataGridView. Only if I close the form and open it again, the changes are being displayed. I want...
0
7518
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7715
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7469
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.