Access data to excel combo box

Status
Not open for further replies.

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
This code I have written in Access database I need to filter this table with a Combo box then add the result data to another Comb box in VBA excel
How is this possible?

VBA Code:
Sub ExportData()

On Error GoTo ErrorHandler

Dim dbTable As String

Dim xlWorksheetPath As String

xlWorksheetPath = "\\TGS-SRV01\Share\ShopFloor\PRODUCTION\DLS Cardworker"

xlWorksheetPath = xlWorksheetPath & "Automated Cardworker.xlsm"

dbTable = "GantryHeight&Width"

DoCmd.TransferSpreadsheet transfertype:=acExport, spreadsheettype:=acSpreadsheetTypeExcel12, tablename:=dbTable, FileName:=xlWorksheetPath, hasfieldnames:=True

ErrorHandlerExit:

Exit Sub

ErrorHandler:

MsgBox "No Data Found”"

Resume ErrorHandlerExit

End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
The other way I tried was this but for some reason, it can`t seem to open access correctly


VBA Code:
Private Function OpenConAndGetRS(qry As String) As Object
    Dim strcon As String
    Dim conn As Object, rs As Object
    Set conn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    rs.CursorLocation = adUseClient
    strcon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\TGS-SRV01\Share\ShopFloor\PRODUCTION\DLS Cardworker\Access Files\DrNo Data Base.accdb;"
    conn.Open strcon
    rs.Open qry, conn, 3, 3
    Set OpenConAndGetRS = rs
End Function

Private Sub Gantry_Height_DropButtonClick()

    Dim qry As String

   qry = "SELECT * FROM [GantryHeight&Width] " & _
    " WHERE [Vehicle]='" & Model_Type.Text & "'"
    Dim rs As Object: Set rs = OpenConAndGetRS(qry)
    If Not (rs.BOF Or rs.EOF) Then
    Do While Not rs.EOF
  
    Me.Gantry_Height.Column = rs.Fields("Height&Width").Value
    rs.MoveNext
    Loop
  
   rs.Close: Set rs = Nothing
    End If
  
End Sub
 
Upvote 0
Duplicate thread, so closed.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top