Hi all,
I'm trying to extract data from an Access DB into an Excel user form (as the intended users will not all have MS Access).
The access table (TblData) has multiple rows and fields, and the SQL query I have created will search the 'CaseRef' field for the value the user puts in to the first text box, and then return the value from 2 specific fields into the two text boxes below.
The issue I am having is that the values that are being returned have the character "¶" added to the end.
Furthermore, if I try to copy the value, it pastes as "??" or two square boxes.
Would someone be able to tell me where I'm going wrong, or what I should change?
The code is below - many thanks for your help!
I'm trying to extract data from an Access DB into an Excel user form (as the intended users will not all have MS Access).
The access table (TblData) has multiple rows and fields, and the SQL query I have created will search the 'CaseRef' field for the value the user puts in to the first text box, and then return the value from 2 specific fields into the two text boxes below.
The issue I am having is that the values that are being returned have the character "¶" added to the end.
Furthermore, if I try to copy the value, it pastes as "??" or two square boxes.
Would someone be able to tell me where I'm going wrong, or what I should change?
The code is below - many thanks for your help!
Code:
Private Sub CommandButton1_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 divsion FROM TblData WHERE CaseRef=" & Nums
Dim Db As String
Db = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\users\user\documents\kyc database.accdb;Persist Security Info=False;"
Dim Nums As String
Nums = Me.CaseNum.Value 'this is the reference the user inputs'
If CaseNum = 0 Then
MsgBox "Please enter a value"
Exit Sub
End If
Cn.Open Db
With Rs
.ActiveConnection = Cn
.Open "SELECT division FROM TblData WHERE CaseRef=" & Nums, _
Cn, adOpenStatic
TestForm.DivBox.Value = Rs.GetString
End With
Rs.Close
With Rs
.ActiveConnection = Cn
.Open "SELECT casehandler FROM TblData WHERE CaseRef=" & Nums, _
Cn, adOpenStatic
TestForm.WorkerBox.Value = Rs.GetString
Rs.Close
Set Rs = Nothing
Cn.Close
Set Cn = Nothing
End With
End Sub