DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: ADO Data Access Problem

Hybrid View

  1. #1
    rsmith555 Guest

    ADO Data Access Problem


    I have a very basic text book which touched on ADO, but I've had problems
    developing an app for work which reads data from an Access 2000 DB. I have
    two ADO controls on my startup form which are linked to the same DB, but
    separate tables. When entering a "job number" (production app) into a text
    field on the form and clicking the "Get Record" command button, the txtjobnum
    control should be updated with the fldjobnum in the database; the Datasource,
    Datafield, Connection String and Recordsource properties (where applicable)
    all seem to be set just right for the controls on the form. The txtjobnum
    text box is not updated properly, however (as is the case with all other
    controls on the form that are linked to the DB). It seems that when I first
    start up the app, enter a job number into the text box and hit the enter
    button ("Get Record" button is set a default button) I get an invalid entry
    (due to Msgbox). If I actually "click" the "Get Record" button, however,
    the controls are updated just fine. And if I clear the form after startup,
    then enter the job number and hit the enter button again, the form is updated
    just fine!! Aaarrgghhh! I'm not very familiar with ADO and relatively new
    at VB, but the code appears to be right. I'm convinced that there are ADO/SQL-related
    methods or something like that which I'm unfamiliar with that are missing
    from my code, but I haven't been able to find anything on the web or help
    file which would tip me off. Below is all of the code from the "Get Command"
    button (for those who have a little time on their hands). If anyone's interested,
    I'll be MORE than happy to send you the entire project for a better look.
    Thanks.

    Private Sub cmdGet_Click()
    Const conBtns = vbOKOnly + vbExclamation + vbDefaultButton1 + vbApplicationModal
    Const conMsg = "Invalid entry:" & vbNewLine & "Please enter a valid job number,
    case number or serial number for search."
    Dim strSearch As String, strFldName As String, intRetVal As Integer, textbox
    As Control, intCount As Integer
    Dim inttemp As Integer

    intOpenRecord = 1

    adoJobProfile.CommandType = adCmdText
    adoRepHist.CommandType = adCmdText

    intCount = 0
    For intCount = 0 To 22
    chkPart(intCount).Enabled = True
    Next intCount
    txtInstr.Enabled = True

    'verify that a job number, case number or serial number
    ' has been entered for record search and assign value to search string
    If Trim(txtJobNum.Text) <> "" Then
    strFldName = "fldJobNum"
    strSearch = Trim(txtJobNum.Text)
    Set textbox = txtJobNum
    Else
    If Trim(txtCaseNum.Text) <> "" Then
    strSearch = Trim(txtCaseNum.Text)
    Set textbox = txtCaseNum
    strFldName = "fldCaseNum"
    Else
    If Trim(txtSerNum.Text) <> "" Then
    strSearch = Trim(txtSerNum.Text)
    Set textbox = txtSerNum
    strFldName = "fldSerialNum"
    Else
    intCount = 0
    For intCount = 0 To 22
    chkPart(intCount).Value = 0
    chkPart(intCount).Enabled = False
    Next intCount
    txtInstr.Enabled = False
    intRetVal = MsgBox(conMsg, conBtns, "Invalid Entry")
    txtJobNum.SetFocus
    Exit Sub
    End If
    End If
    End If

    adoJobProfile.RecordSource = "select fldJobNum, fldCaseNum, fldSerialNum
    from tblJobProfile where " & strFldName _
    & " = '" & strSearch & "'"

    If adoJobProfile.Recordset.Fields(strFldName) <> strSearch Then
    intCount = 0
    For intCount = 0 To 22
    chkPart(intCount).Value = 0
    chkPart(intCount).Enabled = False
    Next intCount
    txtInstr.Enabled = False
    intRetVal = MsgBox(conMsg, conBtns, "Invalid Entry")
    textbox.SelStart = 0
    textbox.SelLength = Len(textbox.Text)
    txtRepair.Text = ""
    Exit Sub

    End If

    adoRepHist.RecordSource = "select * from tblrepairhist where " & strFldName
    _
    & " = '" & strSearch & "'"

    adoJobProfile.Refresh
    adoRepHist.Refresh

    cmdUpdate.Enabled = True
    cmdUpdate.Default = True
    cmdGet.Enabled = False



    End Sub


  2. #2
    Arthur Wood Guest

    Re: ADO Data Access Problem


    Try setting a break-point in the Click event of the Command button, to be
    sure that It is actually firing when you hit the Enter key (rather that clicking
    on the Button). Taht may helpou track down what is actually causing the
    behavior that you are experiencing.

    Arthur Wood


    "rsmith555" <rsmith555@hotmail.com> wrote:
    >
    >I have a very basic text book which touched on ADO, but I've had problems
    >developing an app for work which reads data from an Access 2000 DB. I have
    >two ADO controls on my startup form which are linked to the same DB, but
    >separate tables. When entering a "job number" (production app) into a text
    >field on the form and clicking the "Get Record" command button, the txtjobnum
    >control should be updated with the fldjobnum in the database; the Datasource,
    >Datafield, Connection String and Recordsource properties (where applicable)
    >all seem to be set just right for the controls on the form. The txtjobnum
    >text box is not updated properly, however (as is the case with all other
    >controls on the form that are linked to the DB). It seems that when I first
    >start up the app, enter a job number into the text box and hit the enter
    >button ("Get Record" button is set a default button) I get an invalid entry
    >(due to Msgbox). If I actually "click" the "Get Record" button, however,
    >the controls are updated just fine. And if I clear the form after startup,
    >then enter the job number and hit the enter button again, the form is updated
    >just fine!! Aaarrgghhh! I'm not very familiar with ADO and relatively new
    >at VB, but the code appears to be right. I'm convinced that there are ADO/SQL-related
    >methods or something like that which I'm unfamiliar with that are missing
    >from my code, but I haven't been able to find anything on the web or help
    >file which would tip me off. Below is all of the code from the "Get Command"
    >button (for those who have a little time on their hands). If anyone's interested,
    >I'll be MORE than happy to send you the entire project for a better look.
    >Thanks.
    >
    >Private Sub cmdGet_Click()
    >Const conBtns = vbOKOnly + vbExclamation + vbDefaultButton1 + vbApplicationModal
    >Const conMsg = "Invalid entry:" & vbNewLine & "Please enter a valid job

    number,
    >case number or serial number for search."
    >Dim strSearch As String, strFldName As String, intRetVal As Integer, textbox
    >As Control, intCount As Integer
    >Dim inttemp As Integer
    >
    >intOpenRecord = 1
    >
    >adoJobProfile.CommandType = adCmdText
    >adoRepHist.CommandType = adCmdText
    >
    >intCount = 0
    >For intCount = 0 To 22
    >chkPart(intCount).Enabled = True
    >Next intCount
    >txtInstr.Enabled = True
    >
    >'verify that a job number, case number or serial number
    >' has been entered for record search and assign value to search string
    >If Trim(txtJobNum.Text) <> "" Then
    >strFldName = "fldJobNum"
    >strSearch = Trim(txtJobNum.Text)
    >Set textbox = txtJobNum
    >Else
    >If Trim(txtCaseNum.Text) <> "" Then
    >strSearch = Trim(txtCaseNum.Text)
    >Set textbox = txtCaseNum
    >strFldName = "fldCaseNum"
    >Else
    >If Trim(txtSerNum.Text) <> "" Then
    >strSearch = Trim(txtSerNum.Text)
    >Set textbox = txtSerNum
    >strFldName = "fldSerialNum"
    >Else
    >intCount = 0
    >For intCount = 0 To 22
    >chkPart(intCount).Value = 0
    >chkPart(intCount).Enabled = False
    >Next intCount
    >txtInstr.Enabled = False
    >intRetVal = MsgBox(conMsg, conBtns, "Invalid Entry")
    >txtJobNum.SetFocus
    >Exit Sub
    >End If
    >End If
    >End If
    >
    >adoJobProfile.RecordSource = "select fldJobNum, fldCaseNum, fldSerialNum
    >from tblJobProfile where " & strFldName _
    >& " = '" & strSearch & "'"
    >
    >If adoJobProfile.Recordset.Fields(strFldName) <> strSearch Then
    >intCount = 0
    >For intCount = 0 To 22
    >chkPart(intCount).Value = 0
    >chkPart(intCount).Enabled = False
    >Next intCount
    >txtInstr.Enabled = False
    >intRetVal = MsgBox(conMsg, conBtns, "Invalid Entry")
    >textbox.SelStart = 0
    >textbox.SelLength = Len(textbox.Text)
    >txtRepair.Text = ""
    >Exit Sub
    >
    >End If
    >
    >adoRepHist.RecordSource = "select * from tblrepairhist where " & strFldName
    >_
    >& " = '" & strSearch & "'"
    >
    >adoJobProfile.Refresh
    >adoRepHist.Refresh
    >
    >cmdUpdate.Enabled = True
    >cmdUpdate.Default = True
    >cmdGet.Enabled = False
    >
    >
    >
    >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