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.
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