troubleshooting Question

Search Access Database and populate excel Userform

Avatar of KLM56
KLM56 asked on
Microsoft ExcelVisual Basic ClassicMicrosoft Access
35 Comments3 Solutions1492 ViewsLast Modified:
Hi,

Guys I know I will probably get a lot of questions why I am doing this in Excel and not access. The reason is because we have several users and company will not purchase additional licenses for PC's.

My userform already sends data to access table when the user enter the data and click submit. What I am trying to do now is search the database for records and the results populate in the excel userform so we can make edits to the data.

I added a 2 text box to my form that the users enter the date and the branch no they wish to search. I and not sure how to change the code to accept both criteria.  Currently I have just the date field, but I get a data mismatch when I click the search button. Can you help me get this running?

Thanks

Private Sub CommandButton4_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim searchstring As String
    ' connect to the Access database
    Set cn = New ADODB.Connection
    cn.Open "Provider=Microsoft.Ace.OLEDB.12.0; " & _
        "Data Source=C:\Users\Desktop\TestDBA\Tracking_be.accdb"
    ' open a recordset
    Set rs = New ADODB.Recordset
    search = txtDate.Value
    search2 = txtBranchNo.value
    searchstring = "SELECT businessDate, advances, advanceAmount, denied, newAccounts, stopPayments,wires, cpg,branchLoc FROM tblMsrTotals WHERE [businessDate] = '" & search & "'"
    rs.Open "tblMsrTotals", searchstring, cn, adOpenStatic
    txtbusinessDate.Text = rs.Fields("businessDate") 'or whatever
    txtadvances.Text = rs.Fields("advances") 'or whatever
    txtadvanceAmount.Text = rs.Fields("advanceAmount") 'or whatever
    txtdenied.Text = rs.Fields("denied") 'or whatever
    txtnewAccounts.Text = rs.Fields("newAccounts") 'or whatever
    txtstopPayments.Text = rs.Fields("stopPayments") 'or whatever
    txtwires.Text = rs.Fields("wires") 'or whatever
    txtcpg.Text = rs.Fields("cpg") 'or whatever
    txtbranchLoc.Text = rs.Fields("branchLoc") 'or whatever
        
    Set rs = Nothing

End Sub
ASKER CERTIFIED SOLUTION
IrogSinta

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 35 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 35 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros