Open 1 of 2 User forms dependent on Text input

Mick Peters

Board Regular
Joined
May 18, 2015
Messages
93
Hi I am trying to use just a scanner to operate a in out booking system so there is no need for keyboard or mouse skills by the users, I will simply provide a barcode for in and another for Out. I have 3 user forms 1 for booking in, 1 for booking out and a 3rd which I would like to use to open the correct user form depending on the text Scanned into the 1 text box. I have this code below but I am missing something as it will not open either of the user forms . Could anyone help please?



Code:
Private Sub TxtA_AfterUpdate()
If TxtTxtA.Value = "IN" Then
frmDatainput.Show
If TxtA.Value = "OUT" Then
frmDataReturn.Show
Else: MsgBox "Please enter either IN or OUT"
End If
End If
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi I am trying to use just a scanner to operate a in out booking system so there is no need for keyboard or mouse skills by the users, I will simply provide a barcode for in and another for Out. I have 3 user forms 1 for booking in, 1 for booking out and a 3rd which I would like to use to open the correct user form depending on the text Scanned into the 1 text box. I have this code below but I am missing something as it will not open either of the user forms . Could anyone help please?



Code:
Private Sub TxtA_AfterUpdate()
If TxtTxtA.Value = "IN" Then
frmDatainput.Show
If TxtA.Value = "OUT" Then
frmDataReturn.Show
Else: MsgBox "Please enter either IN or OUT"
End If
End If
End Sub

I believe what you wanted to use was this Select case...end select routine which can check multiple variables in 1 iteration.
Code:
Private Sub TxtA_AfterUpdate()
    Select Case TxtTxtA.Value
        Case "IN"
            frmDatainput.Show
        Case "OUT"
            frmDataReturn.Show
        Case Else
            MsgBox "Please enter either IN or OUT"
    End Select
End Sub
 
Upvote 0
Thank you Rhodie72 that is perfect.
I am almost there now I think.
When I scan in either IN or OUT into txtA on form frmin_out then the correct form is opened. I then scan in the 2 data entry's needed in the opened form and end the onchange VBA with Me.Hide and the form hides but the focus is not back at the original form txtA box.
I have tried adding frmin_out.TxtA.SetFocus to both the open event before it leaves the form and open form after the hide (inturn not at the same time) but neither work.
I have tried unload me but that gets a runtime error Automation error the object invoked has disconnected from its clients.
If I need to open a new post on this please let me know as you have solved the original question.
Thank you again for the help.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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