473,484 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Create 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_Updated 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 2592
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,556 Recognized Expert Moderator MVP
Always happy to oblige Twinny - But enough with the tautology!!
Apr 25 '19 #10
twinnyfo
3,653 Recognized Expert Moderator Specialist
Awwww, Dad! I'm just trying to have some fun!

:-)
Apr 25 '19 #11

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

Similar topics

2
6894
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...
3
10002
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:...
2
9558
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...
3
2830
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...
0
1153
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...
0
11798
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...
7
5100
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...
2
1302
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...
1
3472
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,...
0
7079
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
6949
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
7103
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
7137
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...
1
6809
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
7194
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...
0
5403
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
4527
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...
0
3038
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.