Transfer Data from Access Database to Excel userform

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
203
Office Version
  1. 2013
Platform
  1. Windows
I'm having trouble trying to pull data from an Access database into an Excel userform. I've already accomplished transfer data into Access from Excel userform, but I would like to work both ways to reduce the instability of large amounts of data within the excel sheet.

I have a work in progress of code below.

VBA Code:
Private Sub SearchCB_Click()

    Dim Cn As ADODB.Connection
    Set Cn = New ADODB.Connection
    Dim Rs As ADODB.Recordset
    Set Rs = New ADODB.Recordset
    Dim strDataSQL As String
    strDataSQL = "SELECT division FROM RIPNInfo WHERE Part Number=" & Nums 'this line is where I'm struggling I think.  Not exactly sure how to code this.
    Dim Db As String
    Db = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\users\dans\documents\dest1\database1.accdb;Persist Security Info=False;"
    Nums = Me.dat1.Value 'this is a guess

    Cn.Open Db
        If Me.dat1.Value = Rs.Fields("Part Number").Value Then
            With Rs
            
                .ActiveConnection = Cn
                .Open strDataSQL, Cn, adOpenStatic
                If Me.dat1.Value = Rs.Fields("Part Number").Value Then
                Me.ColorTB.Value = Rs.Fields("Color").Value
                Me.SDescriptionTB.Value = Rs.Fields("Short Description").Value
                Me.LDescriptionTB.Value = Rs.Fields("Long Description").Value
                Me.CustomerTB.Value = Rs.Fields("Customer").Value
                Me.dat3.Value = Rs.Fields("Rev").Value

                        Else
        MsgBox "Part Number does not exist. Verify Part Number is typed in correctly, otherwise contact the Manager", , ""
        End If
            End With
Rs.Close
    outtb.Value = "0"
    failtb.Value = "0"
    Set Rs = Nothing
    cn.Close
    Set cn = Nothing
If Class1.Value = True Then
dat5.Value = "1"
End If
If Class2.Value = True Then
dat5.Value = "2"
End If
If Class3.Value = True Then
dat5.Value = "3"
End If
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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