Specific value is entered on userform unless user overides

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Im working on a userform where the user will enter 6 separate values in 6 separate textboxes followed by a letter which will be entered in textbox7
Currently Textbox 7 value is taken from the user selected option button1 "G" or option button2 "M"

Now 99.9% of the time this value will be G
So im trying to limit the amount of unnecessary clicks on the task for the user & to always have textbox7 value set at G unless the user overides it for M

Any advice for how to get this working.
The lines of code below are what i am using at present to put a value in textbox7
Once a value is entered & after a 2 second delay the userform values are pasted to my worksheet.

It can be as basic as having G as textbox 7 default UNLESS option button M is selected within x amount of seconds to then override textbox7 value otherwise just continue with the default

Thanks

Rich (BB code):
Private Sub TextBox7_Change()
    TextBox7 = UCase(TextBox7)
   If TextBox7.Value <> 0 Then
   Application.Wait (Now + TimeValue("0:00:02")) ' DELAY BEFORE CODE IS TRANSFERED
    Call DISCOCODE
   End If
End Sub
Private Sub OptionButton1_Click() ' UK PCB REMOTE
If OptionButton1.Value = True Then
  TextBox7.Visible = True
  TextBox7.Value = "G"
End If
End Sub
Private Sub OptionButton2_Click() ' UK SUSPENSION REMOTE
If OptionButton2.Value = True Then
  TextBox7.Visible = True
  TextBox7.Value = "M"
End If
End Sub
 
Hi,

I tried buidling a system according to the code you supplied. At the end of Textbox6_Change I wrote "G" to TextBox7. For me there is a logical error in your code: you set up the procedure to check for the contents of TextBox7 and run code. As long as that procedure will run no change to TextBox7 can be made so checking for somebody to press OptionButton2 will not be monitored, the procedure will finish with whatever was entered to start the procedure.

I know my suggestion about using the Inputbox at the end of TB6 isn't the smartest one but it will allow the user to take action and enter different values. Using a Listbox on the UserForm instead of the Optionbuttons might be an alternative but will need a click from the user.

Holger
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,

maybe this could be a way around. Instead of holding the Application through Wait use OnTime to start the checking macro after a given time. Problem might be to find the proper event to start the macro (I used TextBox6_Exit for this sample).

Code behind the userform (mine is named UserForm4):

VBA Code:
Private Sub OptionButton1_Click() ' UK PCB REMOTE
If OptionButton1.Value = True Then
  TextBox7.Value = "G"
End If
End Sub
Private Sub OptionButton2_Click() ' UK SUSPENSION REMOTE
If OptionButton2.Value = True Then
  TextBox7.Value = "M"
End If
End Sub

Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'on leaving TextBix6 "G" is inserted in TextBox7, a global variable
'holding the present value is filled and macro is started
If Len(Me.TextBox6.Value) > 0 Then
  g_varData = "G"
  TextBox7.Value = "G"
  Check_Me
End If
End Sub

In a standard module:

VBA Code:
Public g_varData As Variant

Sub Check_Me()
Application.OnTime Now + TimeValue("00:00:05"), "my_Procedure"
End Sub

Sub my_Procedure()
If UserForm4.TextBox7.Value = g_varData Then
  Call DISCOCODE
Else
  g_varData = UserForm4.TextBox7.Value
  Application.OnTime Now + TimeValue("00:00:05"), "my_Procedure"
End If
'/// added to unload the UserForm
Unload UserForm4
End Sub

Sub DISCOCODE()
  '/// put your code here
  '/// for control I just print content of TB7
  Debug.Print UserForm4.TextBox7.Value
End Sub

HTH
Holger
 
Upvote 0
Thanks for your time but that stil soesnt allow the user to select the M option !% for it to work.

I think i will just have to leave it as it is.
 
Upvote 0
Hi ipbr21054,

be assured that I tested the code before posting it here. I added

VBA Code:
Private Sub TextBox7_Change()
Debug.Print Now
Debug.Print TextBox7.Value
End Sub

and found

Rich (BB code):
03.01.2023 13:21:49 
G
03.01.2023 13:21:51 
M

in the Immediate Window which correspond to the view of change in TextBox7 while the code is running.

You can find the workbook for download to test here.

Holger
 
Upvote 0
I see no option to download only view but then i only see a blank worksheet
 
Upvote 0
Hi,

I see the menu in german (the english commands may differ as I translated them):

  • Datei - File
  • Seichern Unter - SaveAs
  • Eine Kopie herunterladen - Download a Copy
and download should start to the folder specified in your browser.

Holger
 
Upvote 0

Forum statistics

Threads
1,224,852
Messages
6,181,400
Members
453,035
Latest member
chrismor_gr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top