• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 42
  • Last Modified:

Store Value from one form and then ask for a multiplier in second form

Again, I am horrible in Excel VBA so please take it easy on me.

What I am trying to do is store a numerical value of a barcode in UserForm7.Textbox1 using the first set of code then have the application wait 2 seconds and then open UserForm8 and store an integer that is hand-typed  in Userform8.Texbox1.  Then on button click it looks up the barcode value in the sheet, shifts one cell to the right, and adds the muliple from UserForm8.TextBox1 to the number that already exists in that cell.  Running into all kinds of issues but the first was I had UserForm7 and UserForm8 showing up at the same time.

I can certainly add more code or upload the file if it helps you help me.

Private Sub TextBox1_Change()

If Not IsActive And TextBox1.Text <> "" Then
  
  IsActive = True
  Application.OnTime Now + TimeValue("00:00:03"), "UserForm7.Hide"
  UserForm8.Show
End If

End Sub



Private Sub UserForm_Initialize()


IsActive = False
TextBox1.SetFocus
  
End Sub

Open in new window


Private Sub btn_MultipleAdd_Click()
Worksheets("Main").Unprotect
Dim TargetCell As Range
Dim TextBox1 As Integer
If WorksheetFunction.CountIf(Sheets("Main").Columns(4), TextBox1.Value) = 1 Then
    Set TargetCell = Sheets("Main").Columns(4).Find(TextBox1.Value, , xlValues, xlWhole).Offset(0, 1)
    TargetCell.Value = TargetCell.Value + TextBox1
    TextBox1.Value = ""
    TextBox1.SetFocus
Else
    MsgBox "Item Not Found"
End If
Worksheets("Main").Protect
End Sub

Open in new window

0
rmc71291
Asked:
rmc71291
  • 2
1 Solution
 
Roy CoxGroup Finance ManagerCommented:
It would be simpler to have one UserForm, but use a MultiPage control.

if not then you need to declare a Global variable that will store the bar code
0
 
rmc71291Author Commented:
Just to close out the topic, I was able to do this on my own but using a single form.  I'm pretty proud of myself because this is the first time I've really written code myself.  Of course pieces of it are scavenged from others but I made it all work myself.  Probably not much to you guys but I fell like a big boy now.

Private Sub UserForm_Initialize()
  
  IsActive = False
  TextBox1.SetFocus
  
End Sub

Private Sub TextBox1_Change()

If Not IsActive And TextBox1.Text <> "" Then
  
  IsActive = True
  Application.OnTime Now + TimeValue("00:00:03"), "Module13.Multiplier"
  
End If

End Sub

Open in new window


Sub Multiplier()
UserForm7.TextBox2.SetFocus
End Sub

Open in new window


Private Sub MultiAdd_Click()
Worksheets("Main").Unprotect
Dim TargetCell As Range
If WorksheetFunction.CountIf(Sheets("Main").Columns(4), TextBox1.Value) = 1 Then
    Set TargetCell = Sheets("Main").Columns(4).Find(TextBox1.Value, , xlValues, xlWhole).Offset(0, 1)
    TargetCell.Value = TargetCell.Value + TextBox2.Value
    TextBox1.Value = ""
    TextBox2.Value = ""
    TextBox1.SetFocus
Else
    MsgBox "Item Not Found"
End If
Worksheets("Main").Protect

End Sub

Open in new window

0
 
rmc71291Author Commented:
Other responses did not quite answer as asked but offered reasonable alternatives.  In the end, I chose a different route than the original question or the alternate solutions.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now