Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Sep 2007
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populating Text Boxes from Combo Box selection (Access 2003)

    Hey people. I know I have already asked this same question, but it's got a different twist to it. I had a co-worker help me with some code that we wrote into the database to display Amperage, and Voltage. I also re-wrote some of the tables to make it a little easier for it to run. Except, now the database is over 5MB, so it's hard to transfer. But, I have had to edit the code to help to populate another Text box that I have added, called "Speed". I went through the code, and edited what I thought would need to be fixed, but to no avail. If someone could help me, that would be great. Here is the code.


    Sub DumpAmpsVoltsSpeed()
    Dim HoldAssetNumber As Integer
    Dim HoldWeldNumber As Integer
    Dim HoldWeldBreakdown As Integer
    Dim HoldAmps As String
    Dim HoldVolts As String
    Dim HoldSpeed As String

    Dim dbobject As DAO.Database
    Dim AmpVoltSpeedRS As DAO.Recordset
    Dim strQuery As String

    Set dbobject = CurrentDb
    strQuery = "SELECT * FROM tblWeld;"
    Set AmpVoltSpeedRS = dbobject.OpenRecordset(strQuery)

    HoldAssetNumber = Forms![frmMainSwitch].AssetNumber.Value
    HoldWeldNumber = Forms![frmMainSwitch].WeldNumber.Value

    With AmpVoltSpeedRS
    .MoveFirst
    Do While Not .EOF
    If .Fields("AssetID").Value = HoldAssetNumber And .Fields("WeldNumber").Value = HoldWeldNumber And .Fields("WeldBreakdownNumber").Value = HoldWeldBreakdown Then
    HoldAmps = .Fields("Amperage").Value
    HoldVolts = .Fields("Voltage").Value
    HoldSpeed = .Fields("Speed").Value

    End If
    .MoveNext
    Loop
    End With

    Forms![frmMainSwitch].Amperage.Value = HoldAmps
    Forms![frmMainSwitch].Voltage.Value = HoldVolts
    Forms![frmMainSwitch].Speed.Value = HoldSpeed

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Populating Text Boxes from Combo Box selection (Access 2003)

    I'm not sure what your question is, but I have a few comments.

    1) It seems inefficient to loop through the entire recordset. It would be much faster to go directly to the record you need using FindFirst.
    2) You use a variable HoldWeldBreakdown but you do not assign it a value, so it'll always be 0.

  3. #3
    Lounger
    Join Date
    Sep 2007
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populating Text Boxes from Combo Box selection (Access 2003)

    Hans,

    I am not totally sure about the loop. This was a code that a co-worker had "borrowed" from another database, so I doubt it is the best fit. I remeber you help me to display the information into my textboxes earlier, but when he helped me work on something else, he said it would be better to use a Macro and code to populate the text boxes, rather than the Control Source. Basically, I just would like to populate some text boxes with the information that is containedin my tblWeld, which has all the information. But, since this code is already in my database, I would just like it to populate all the text boxes that I am displaying. "Voltage", "Amperage", and "Speed". It was working, until I needed to edit the tables, and now, it doesn't work at all. What should the value be of HoldWeldBreakdown, if it is based on the previous combo box?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Populating Text Boxes from Combo Box selection (Access 2003)

    Add

    HoldWeldBreakdown = Forms![frmMainSwitch].WeldNumberBreakdown.Value

    below the lines that set HoldAssetNumber and HoldWeldNumber.

    And change

    With AmpVoltSpeedRS
    .MoveFirst
    Do While Not .EOF
    If .Fields("AssetID").Value = HoldAssetNumber And .Fields("WeldNumber").Value = HoldWeldNumber And .Fields("WeldBreakdownNumber").Value = HoldWeldBreakdown Then
    HoldAmps = .Fields("Amperage").Value
    HoldVolts = .Fields("Voltage").Value
    HoldSpeed = .Fields("Speed").Value
    End If
    .MoveNext
    Loop
    End With

    to

    With AmpVoltSpeedRS
    .FindFirst "AssetID = " & HoldAssetNumber & " And WeldNumber = " & HoldWeldNumber & " And WeldBreakdownNumber = " & HoldWeldBreakdown
    If Not .NoMatch Then
    HoldAmps = .Fields("Amperage").Value
    HoldVolts = .Fields("Voltage").Value
    HoldSpeed = .Fields("Speed").Value
    End If
    End With

  5. #5
    Lounger
    Join Date
    Sep 2007
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populating Text Boxes from Combo Box selection (Access 2003)

    Thanks for the help. Works great now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •