Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:47:24+00:00 2026-06-12T19:47:24+00:00

Good-day, I’m experiencing a very strange event that just started happening. Whenever I press

  • 0

Good-day,

I’m experiencing a very strange event that just started happening. Whenever I press the ENTER button on my keyboard, I expect the KeyDown event of my textbox to be raised and the corresponding code run. Instead, the form disappears (as if the .Hide() method has been called). When I debug, I see that the code that’s supposed to run after the KeyDown event is raised is executing accordingly – but the form just disappears.

I’ve never encountered this before, so I don’t know what to do. Any help would be appreciated. Thanks.

HERE’S THE CODE OF MY FORM:

Imports System.Net
Imports MySql.Data
Imports MySql.Data.MySqlClient

Public Class FormAdd

#Region "VARIABLE DECLARATIONS CODE"

'FOR MySQL DATABASE USE
Public dbConn As MySqlConnection

'FOR CARD NUMBER FORMATTING
Private CF As New CardFormatter

'FOR CARD ENCRYPTION
Dim DES As New System.Security.Cryptography.TripleDESCryptoServiceProvider
Dim Hash As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim encryptedCard As String

#End Region

#Region "SUB-ROUTINES AND FUNCTIONS"

Private Sub GetDBdata()

    Try
        If TextBoxAccount.Text = "" Then
            MessageBox.Show("Sorry, you must enter an ACCOUNT# before proceeding!")
            TextBoxAccount.Focus()
        Else
            dbConn = New MySqlConnection
            dbConn.ConnectionString = String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password)
            If dbConn.State = ConnectionState.Open Then
                dbConn.Close()
            End If
            dbConn.Open()
            Dim dbAdapter As New MySqlDataAdapter("SELECT * FROM customer WHERE accountNumber = " & TextBoxAccount.Text, dbConn)
            Dim dbTable As New DataTable
            dbAdapter.Fill(dbTable)
            If dbTable.Rows.Count > 0 Then
                'MessageBox.Show("Customer Account Found!")
                Call recordFound()
                TextBoxLastName.Text = dbTable.Rows(0).Item("nameLAST")
                TextBoxFirstName.Text = dbTable.Rows(0).Item("nameFIRST")
                TextBoxSalutation.Text = dbTable.Rows(0).Item("nameSALUTATION")
                TextBoxCompanyName.Text = dbTable.Rows(0).Item("nameCOMPANY")
            Else
                'MessageBox.Show("No Customer Records Found!  Please try again!")
                Call recordNotFound()
                ButtonReset.PerformClick()
            End If
            dbConn.Close()
        End If
    Catch ex As Exception
        MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
                        vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
    End Try
    Dispose()

End Sub

Private Sub SetDBData()

    Try
        dbConn = New MySqlConnection
        dbConn.ConnectionString = String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password)
        Dim noCard As Boolean = True
        If dbConn.State = ConnectionState.Open Then
            dbConn.Close()
        End If
        dbConn.Open()
        Dim dbQuery As String = "SELECT * FROM cc_master WHERE ccNumber = '" & TextBoxCard.Text & "';"
        Dim dbData As MySqlDataReader
        Dim dbAdapter As New MySqlDataAdapter
        Dim dbCmd As New MySqlCommand
        dbCmd.CommandText = dbQuery
        dbCmd.Connection = dbConn
        dbAdapter.SelectCommand = dbCmd
        dbData = dbCmd.ExecuteReader
        While dbData.Read()
            If dbData.HasRows() = True Then
                MessageBox.Show("This Credit/Debit Card Already Exists!  Try Another!")
                noCard = False
            Else
                noCard = True
            End If
        End While
        dbData.Close()
        If noCard = True Then
            'PERFORM CARD ENCRYPTION


            'PERFORM DATABASE SUBMISSION
            Dim dbQuery2 As String = "INSERT INTO cc_master (ccType, ccNumber, ccExpireMonth, ccExpireYear, ccZipcode, ccCode, ccAuthorizedUseStart, ccAuthorizedUseEnd, customer_accountNumber)" & _
                "VALUES('" & ComboBoxCardType.SelectedItem & "','" & TextBoxCard.Text & "','" & TextBoxExpireMonth.Text & "','" & TextBoxExpireYear.Text & _
                "','" & TextBoxZipCode.Text & "','" & TextBoxCVV2.Text & "','" & Format(DateTimePickerStartDate.Value, "yyyy-MM-dd HH:MM:ss") & "','" & Format(DateTimePickerEndDate.Value, "yyyy-MM-dd HH:MM:ss") & "','" & TextBoxAccount.Text & "');"
            Dim dbData2 As MySqlDataReader
            Dim dbAdapter2 As New MySqlDataAdapter
            Dim dbCmd2 As New MySqlCommand
            dbCmd2.CommandText = dbQuery2
            dbCmd2.Connection = dbConn
            dbAdapter2.SelectCommand = dbCmd2
            dbData2 = dbCmd2.ExecuteReader
            MessageBox.Show("Credit/Debit Card Information Saved SUCCESSFULLY!")
            ButtonReset.PerformClick()
        End If
        dbConn.Close()
    Catch ex As Exception
        MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
                        vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
    End Try
    Dispose()

End Sub

Private Sub ResetForm()
    TextBoxAccount.Clear()
    TextBoxLastName.Clear()
    TextBoxFirstName.Clear()
    TextBoxSalutation.Clear()
    TextBoxCard.Clear()
    ComboBoxCardType.SelectedItem = ""
    TextBoxCompanyName.Clear()
    TextBoxCVV2.Clear()
    TextBoxExpireMonth.Clear()
    TextBoxExpireYear.Clear()
    TextBoxZipCode.Clear()
    CheckBoxConfirm.Checked = False
    TextBoxAccount.SelectionStart = 0
    TextBoxAccount.SelectionLength = Len(TextBoxAccount.Text)
    TextBoxAccount.Focus()
    GroupBoxInputError.Hide()
    LabelInstruction.Show()
    GroupBox1.Height = 75


End Sub

Private Sub recordFound()

    GroupBoxInputError.Text = ""
    LabelError.BackColor = Color.Green
    LabelError.ForeColor = Color.White
    LabelError.Text = "RECORD FOUND!"
    GroupBoxInputError.Visible = True
    GroupBox1.Height = 345
    ButtonReset.Show()
    LabelInstruction.Hide()
    ComboBoxCardType.Focus()

End Sub

Private Sub recordNotFound()

    GroupBoxInputError.Text = ""
    LabelError.BackColor = Color.Red
    LabelError.ForeColor = Color.White
    LabelError.Text = "NO RECORD FOUND!"
    GroupBoxInputError.Visible = True


End Sub

'Public Sub encryptCard()
'    Try
'        DES.Key = Hash.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(My.Settings.Key))
'        DES.Mode = System.Security.Cryptography.CipherMode.ECB
'        Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = DES.CreateEncryptor
'        Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(TextBoxCard.Text)
'        TextBoxCard.Text = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
'    Catch ex As Exception
'        MessageBox.Show("The following error(s) have occurred: " & ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
'    End Try
'End Sub

#End Region

#Region "TOOLSTRIP MENU CONTROL CODE"

Private Sub ExitAltF4ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitAltF4ToolStripMenuItem.Click
    End
End Sub

#End Region

#Region "BUTTON CONTROLS CODE"

Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExit.Click
    FormMain.Show()
    Me.Close()
End Sub

Private Sub ButtonReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReset.Click
    Call ResetForm()
End Sub

Private Sub ButtonSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSubmit.Click
    Call SetDBData()
    Call ResetForm()
End Sub

Private Sub ButtonEncrypt_Click(sender As System.Object, e As System.EventArgs) Handles ButtonEncrypt.Click

End Sub

#End Region

#Region "FORM CONTROLS CODE"

Private Sub FormAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Control.CheckForIllegalCrossThreadCalls = False
    TextBoxAccount.Focus()
    Me.KeyPreview = True


    Timer1.Enabled = True
    Timer1.Interval = 1

    GroupBoxInputError.Hide()
    ButtonSubmit.Hide()
    ButtonReset.Hide()
    GroupBox1.Height = 75

    'LabelFooter.Text = "Welcome  " & FormLogin.TextBoxUsername.Text() & "   |   Timestamp:    " & Date.Now.ToString
    Try
        LabelIP.Text = "IP:  " & Dns.GetHostEntry(Dns.GetHostName).AddressList(0).ToString
    Catch ex As Exception

    End Try

    'Populate the Card Type combobox with the list of card types from the CardFormatter class
    ComboBoxCardType.Items.AddRange(CF.GetCardNames.ToArray)

End Sub


#End Region

#Region "TEXTBOX CONTROLS CODE"

Private Sub TextBoxCard_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBoxCard.GotFocus

    TextBoxCard.SelectionStart = 0
    TextBoxCard.SelectionLength = Len(TextBoxCard.Text)
    Me.Refresh()

End Sub


Private Sub TextBoxCard_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBoxCard.LostFocus

    '//CARD VALIDATION//
    '   This code will check whether the card is a valid number or not.  It doesn't check to see if the card is active.
    '   The code calls on the creditcard function stored in MyModules.vb
    Try
        If creditcard(TextBoxCard.Text) Then
            'MsgBox("Card is Valid")
            TextBoxCard.BackColor = Color.GreenYellow
            TextBoxCard.ForeColor = Color.Black
            GroupBoxInputError.Visible = False
            TextBoxCard.Text = CF.GetFormattedString(ComboBoxCardType.Text, TextBoxCard.Text)
            Me.Refresh()
        Else
            BWErrorNotice.RunWorkerAsync()
            'MsgBox("Invalid Card")
            GroupBoxInputError.Visible = True
            TextBoxCard.Focus()
            TextBoxCard.Text = TextBoxCard.Text.Replace("-", "")
            Me.Refresh()
        End If
    Catch ex As Exception

    End Try

End Sub

Private Sub TextBoxAccount_GotFocus(sender As Object, e As System.EventArgs) Handles TextBoxAccount.GotFocus
    TextBoxAccount.SelectAll()
End Sub

Private Sub TextBoxAccount_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBoxAccount.KeyDown

    If e.KeyCode = Keys.Enter Then
        e.SuppressKeyPress = True
        If TextBoxAccount.Text <> "" Then
            Call GetDBdata()
        Else
            MsgBox("You must enter an account number!", MsgBoxStyle.Exclamation, "ATTENTION PLEASE!")
            TextBoxAccount.Focus()
        End If
    End If

    'If e.KeyCode = Keys.Enter Then
    '    e.Handled = True
    '    SendKeys.Send("{Tab}")
    'End If

End Sub

Private Sub TextBoxCard_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBoxCard.MouseClick
    TextBoxCard.SelectionStart = 0
    TextBoxCard.SelectionLength = Len(TextBoxCard.Text)
    TextBoxCard.Text = TextBoxCard.Text.Replace("-", "")
    Me.Refresh()
End Sub

#End Region

#Region "OTHER/MISCELLANEOUS CONTROLS CODE"

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    LabelDateTime.Text = DateTime.Now

End Sub

Private Sub BWErrorNotice_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BWErrorNotice.DoWork

    Do While Not creditcard(TextBoxCard.Text)
        LabelError.BackColor = Color.Black
        System.Threading.Thread.Sleep(500)
        LabelError.BackColor = Color.Red
        System.Threading.Thread.Sleep(500)
    Loop
    BWErrorNotice.CancelAsync()

End Sub

Private Sub CheckBoxConfirm_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBoxConfirm.CheckedChanged
    If CheckBoxConfirm.Checked = True Then
        ButtonSubmit.Show()
    Else
        ButtonSubmit.Hide()
    End If
End Sub

#End Region

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:47:25+00:00Added an answer on June 12, 2026 at 7:47 pm

    I figured out the problem. I was calling Dispose() at the end of my GetDBData() function – so the form was getting disposed before execution returned back to the TextBox. I deleted it and all is well again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, I have found a strange quirk in Vim that I can't explain
Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good day, just a quick question: I would like to bind a table to
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day, all. I know that this is a pretty basic question in terms
Good Day, I have a simple working routine in Perl that swaps two words:
Good day, Stack Overflow. I have a homework assignment that I'm working on this
Good day everyone. I need your skills with g++ to understand what's happening to
Good day all, I have written an application that i require to have a
Good day code knights, I have a tricky problem that I cannot see a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.