Hi,
I am new to this forum so it's my first post here.
I am having a problem with a program that I wrote in VB6. I am new to programming so have lots of problems. I am sharing the first problem here.
In a form, I have created two text box one with First Name and another with Last Name, finally the submit button to save the data. The problem is that when I click the command button with textbox1 as empty, it shows the error message but doesn't focus to textbox1 and jumps forward. My sample code is given below:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Text2.SetFocus
End If
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Command1.SetFocus
End If
End Sub
Private Sub Command1_Click()
If Len(Trim(Text2.Text)) > 0 And Len(Trim(Text1.Text)) = 0 Then
MsgBox "Text 1 is empty", vbInformation, "Error"
If response = vbOK Then
Text1.SetFocus
Cancel = True
Else
MsgBox "Program ran fine", vbInformation, "Alert"
Unload Me
End If
End If
End Sub
Is there any way to get out of this ?
I am new to this forum so it's my first post here.
I am having a problem with a program that I wrote in VB6. I am new to programming so have lots of problems. I am sharing the first problem here.
In a form, I have created two text box one with First Name and another with Last Name, finally the submit button to save the data. The problem is that when I click the command button with textbox1 as empty, it shows the error message but doesn't focus to textbox1 and jumps forward. My sample code is given below:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Text2.SetFocus
End If
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Command1.SetFocus
End If
End Sub
Private Sub Command1_Click()
If Len(Trim(Text2.Text)) > 0 And Len(Trim(Text1.Text)) = 0 Then
MsgBox "Text 1 is empty", vbInformation, "Error"
If response = vbOK Then
Text1.SetFocus
Cancel = True
Else
MsgBox "Program ran fine", vbInformation, "Alert"
Unload Me
End If
End If
End Sub
Is there any way to get out of this ?