Results 1 to 3 of 3
  1. #1
    dualvba's Avatar
    dualvba is offline Novice
    Windows Vista Access 2003
    Join Date
    Apr 2012
    Location
    Kent, UK
    Posts
    18

    Red face Selection VBA on Form

    Hi



    I have created a form, using only VBA code.

    However, what do I need to change, in the Materials Code below, to make it select only Materials in the pick list, for the supplier picked in the Supplier box above, please?

    The form, basically, asks you to select a Supplier first, from a picklist, and it shows the suppliers details, then the material box, currently shows the entire list of materials, I'd like it to show the materials only, for that supplier to pick from, then you click analyse, and it shows in the bottom box, the list of comms from a comms log table, between us and the supplier, the small count box at the moment, simply just adds the total number of comms.

    Thanks so much, here's my code, it clears the supplier and material details each time you select a new supplier, and then material:

    Private Sub cmbSupplier_AfterUpdate()
    Dim strSupplier As String
    Dim dbdata As DAO.Database
    Dim rstSupplier As DAO.Recordset
    strSupplier = Me.cmbSupplier.Value
    Set dbdata = CurrentDb
    Set rstSupplier = dbdata.OpenRecordset("SELECT * from tblSuppliersList WHERE SupplierDetails = " & Chr(34) & strSupplier & Chr(34))
    'MsgBox strSupplier
    Call DeleteSupplierDetails
    Me.lstSupplierDetails.RowSourceType = "Value List"
    Me.lstSupplierDetails.ColumnCount = 2
    Me.lstSupplierDetails.AddItem "Supplier Details;" & rstSupplier.Fields("SupplierDetails")
    Me.lstSupplierDetails.AddItem "Supplier ID;" & rstSupplier.Fields("SupplierID")
    End Sub

    Sub DeleteSupplierDetails()
    Dim intSupplierName As Integer
    Me.lstSupplierDetails.RowSourceType = "Value List"
    For intSupplierName = Me.lstSupplierDetails.ListCount - 1 To 0 Step -1
    Me.lstSupplierDetails.RemoveItem (intSupplierName)
    Next intSupplierName
    End Sub

    Private Sub cmbMaterial_AfterUpdate()
    Dim strMaterial As String
    Dim dbdata As DAO.Database
    Dim rstMaterial As DAO.Recordset
    strMaterial = Me.cmbMaterial.Value
    Set dbdata = CurrentDb
    Set rstMaterial = dbdata.OpenRecordset("SELECT * from tblmaterialslist WHERE MaterialDescription = " & Chr(34) & strMaterial & Chr(34))
    'MsgBox strMaterial
    Call DeleteMaterialDetails
    Me.lstMaterialDetails.RowSourceType = "Value List"
    Me.lstMaterialDetails.ColumnCount = 2
    Me.lstMaterialDetails.AddItem "Material Record ID;" & rstMaterial.Fields("MaterialRecordID")
    Me.lstMaterialDetails.AddItem "Material Name;" & rstMaterial.Fields("MaterialName")
    Me.lstMaterialDetails.AddItem "Material ID;" & rstMaterial.Fields("MaterialID")
    End Sub

    Sub DeleteMaterialDetails()
    Dim intMaterialName As Integer
    Me.lstMaterialDetails.RowSourceType = "Value List"
    For intMaterialName = Me.lstMaterialDetails.ListCount - 1 To 0 Step -1
    Me.lstMaterialDetails.RemoveItem (intMaterialName)
    Next intMaterialName
    End Sub
    Attached Files Attached Files

  2. #2
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    All of the above seems a bit over complicated. If all of the information you are wanting to cue off of is connected in a table/tables, why not set the Row Source Type to Table/Query? See the other thread I just guided someone else one.

    https://www.accessforums.net/showthr...x-with-subform

    Hope that helps.

  3. #3
    dualvba's Avatar
    dualvba is offline Novice
    Windows Vista Access 2003
    Join Date
    Apr 2012
    Location
    Kent, UK
    Posts
    18
    Oh brill, thank you, I'll look into that

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Populate Form by Combo Box Selection, Editable?
    By access_student in forum Forms
    Replies: 1
    Last Post: 03-26-2012, 10:10 AM
  2. combo box selection to update form
    By sartan2002 in forum Forms
    Replies: 6
    Last Post: 02-03-2012, 01:47 PM
  3. Selection form help required!
    By REAPER_110 in forum Forms
    Replies: 3
    Last Post: 05-20-2011, 10:13 AM
  4. Form dropdown selection
    By piper in forum Forms
    Replies: 2
    Last Post: 04-16-2011, 09:34 AM
  5. Replies: 0
    Last Post: 02-09-2007, 09:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums