Change event reading info from database


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Change event reading info from database

Hybrid View

  1. #1
    Tommy Guest

    Change event reading info from database


    I open up a database and read in the first record, but when I try to search
    by a field the data will not change. After debugging, the query string holds
    the info but the when it is time to change, the text box change event does
    not take place. It only stores the current record.

    Private Sub cmdSerial_Click()
    Dim searchSerial As String

    Dim rsSearch As ADODB.Recordset
    Dim searchQuery As String

    searchSerial = InputBox("Enter Serial Number to Search")
    Set rsSearch = New ADODB.Recordset
    searchQuery = "SELECT * FROM SerialNumber Where CBSerialNumber ='" & _
    Trim(searchSerial) & "'"
    rsSearch.Open searchQuery, cnSerialNumber, adOpenStatic, adLockPessimistic
    If rsSearch.RecordCount > 0 Then
    MsgBox "Serial Number Not Found"
    Else
    If rsSearch.BOF = True Or rsSearch.EOF = True Then
    Exit Sub
    End If
    txtSerial = rsSerialNumber!CBSerialNumber
    txtType = rsSerialNumber!New_Upgrade
    txtMotherboard = rsSerialNumber!Motherboard
    txtHarddrive = rsSerialNumber!HardDrive
    txtCd = rsSerialNumber!CD_ROM
    txtCdrw = rsSerialNumber!CDRW_DVDRW
    txtFloppy = rsSerialNumber!Floppy
    txtNetworkCard = rsSerialNumber!NetworkCard
    txtHardware = rsSerialNumber!OtherHardware
    txtSpeakers = rsSerialNumber!Speakers
    txtOS = rsSerialNumber!OperatingSystem
    txtProduct = rsSerialNumber!ProductKey
    txtNetworkType = rsSerialNumber!TypeNetwork
    txtUser = rsSerialNumber!UserName
    txtPassword = rsSerialNumber!Password
    End If

    End Sub



  2. #2
    Arthur Wood Guest

    Re: Change event reading info from database


    Just a quick comment:

    this code looks VERY suspect:

    rsSearch.Open searchQuery, cnSerialNumber, adOpenStatic, adLockPessimistic
    If rsSearch.RecordCount > 0 Then
    MsgBox "Serial Number Not Found"
    Else
    If rsSearch.BOF = True Or rsSearch.EOF = True Then
    Exit Sub
    End If
    txtSerial = rsSerialNumber!CBSerialNumber

    You are testing the RecordCount (which is generally NOT a good idea, unless
    you have a CLIENT-SIDE cursor. The RecordCount property is NOT accurate until
    the Recordset has been FULLY populated, and that USUALLY requires a recordset.MoveLast),
    and if it is Greater than 0 (which would indicate that you have FOUND AT
    LEAST ONE RECORD), you display a MsgBox saying the the Serial Number WAS
    NOT found???? (you found at least 1 record, but the serial number was not
    found? This makes NO Sense)

    Arthur Wood


    "Tommy" <lavon326@surfsouth.com> wrote:
    >
    >I open up a database and read in the first record, but when I try to search
    >by a field the data will not change. After debugging, the query string holds
    >the info but the when it is time to change, the text box change event does
    >not take place. It only stores the current record.
    >
    >Private Sub cmdSerial_Click()
    >Dim searchSerial As String
    >
    >Dim rsSearch As ADODB.Recordset
    >Dim searchQuery As String
    >
    >searchSerial = InputBox("Enter Serial Number to Search")
    >Set rsSearch = New ADODB.Recordset
    >searchQuery = "SELECT * FROM SerialNumber Where CBSerialNumber ='" & _
    > Trim(searchSerial) & "'"
    >rsSearch.Open searchQuery, cnSerialNumber, adOpenStatic, adLockPessimistic
    > If rsSearch.RecordCount > 0 Then
    > MsgBox "Serial Number Not Found"
    > Else
    > If rsSearch.BOF = True Or rsSearch.EOF = True Then
    > Exit Sub
    > End If
    >txtSerial = rsSerialNumber!CBSerialNumber
    >txtType = rsSerialNumber!New_Upgrade
    >txtMotherboard = rsSerialNumber!Motherboard
    >txtHarddrive = rsSerialNumber!HardDrive
    >txtCd = rsSerialNumber!CD_ROM
    >txtCdrw = rsSerialNumber!CDRW_DVDRW
    >txtFloppy = rsSerialNumber!Floppy
    >txtNetworkCard = rsSerialNumber!NetworkCard
    >txtHardware = rsSerialNumber!OtherHardware
    >txtSpeakers = rsSerialNumber!Speakers
    >txtOS = rsSerialNumber!OperatingSystem
    >txtProduct = rsSerialNumber!ProductKey
    >txtNetworkType = rsSerialNumber!TypeNetwork
    >txtUser = rsSerialNumber!UserName
    >txtPassword = rsSerialNumber!Password
    >End If
    >
    >End Sub
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center