My program calls a form with
Form has a couple of combo boxes and a some text boxes. On the leave event of the zipcode combo box I check the user entered zipcode against a master table and if it is not found, allow the user to add the zip after prompting for the City and State.
After the End Sub statement, it returns to the form show statement rather than staying in the frmAddLocaton form to complete the code there.
I assumed after completing the code in the combo leave sub, control would return to the form. What am I missing?
Code:
frmAddLocation.ShowDialog()
After the End Sub statement, it returns to the form show statement rather than staying in the frmAddLocaton form to complete the code there.
I assumed after completing the code in the combo leave sub, control would return to the form. What am I missing?
Code:
Private Sub cboZip_Leave(sender As Object, e As System.EventArgs) Handles cboZip.Leave
Dim strSQL As New System.Text.StringBuilder
Dim rsZip As New ADODB.Recordset
Dim strTemp As String
If cboZip.Text <> "" Then
strTemp = Trim(Microsoft.VisualBasic.Left(cboZip.Text, 9))
If IsNumeric(strTemp) = False Then
strTemp = Microsoft.VisualBasic.Left(cboZip.Text, 5)
If IsNumeric(strTemp) = False Then
MessageBox.Show("Invalid zipcode (Remove '-' from Zip+4)", MsgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error)
cboZip.Focus()
Exit Sub
End If
End If
strSQL.Clear()
strSQL.Append("SELECT * FROM dba.zip_master WHERE zipid = '")
strSQL.Append(strTemp)
strSQL.Append("'")
rsZip.Open(strSQL.ToString, dbIMS)
If rsZip.EOF = True Then
DialogResult = MessageBox.Show("Zipcode does not exist in master table, do you wish to add?", MsgBoxTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If DialogResult = Windows.Forms.DialogResult.Yes Then
Dim strCity As String = InputBox("City:", MsgBoxTitle)
Dim strState As String = InputBox("State (2 letter abreviation):", MsgBoxTitle)
strSQL.Clear()
strSQL.Append("INSERT INTO dba.zip_master (zipid,city,state,createdby,createddt,srno) VALUES(")
strSQL.Append("'")
strSQL.Append(strTemp) 'zipid
strSQL.Append("','")
strSQL.Append(strCity) 'city
strSQL.Append("','")
strSQL.Append(strState) 'state
strSQL.Append("','")
strSQL.Append("cvinterface") 'createdby
strSQL.Append("','")
strSQL.Append(fnFormatDate(Now, "System", "Y-M-D H:M:SD")) 'createddt
strSQL.Append("',")
lngZipID = fnGetNextID("zip_master") + 1
strSQL.Append(lngZipID) 'srno
strSQL.Append(")")
dbIMS.Execute(strSQL.ToString)
strTemp = cboZip.Text & " " & strCity & ", " & strState
cboZip.Text = strTemp
Else
rsZip.Close()
Exit Sub
End If
Else
lngZipID = rsZip.Fields("srno").Value
strTemp = rsZip.Fields("zipid").Value & " " & rsZip.Fields("city").Value & ", " & rsZip.Fields("state").Value
cboZip.Text = strTemp
End If
rsZip.Close()
End If
End Sub