Do not use on any
shared computer
July 25, 2008 05:48pm pdt
null
[x]
Attachment Details

VBA: How to lookup/update Access database thru Excel Userform?

Tags: vba, excel, access, database, update
I'm new to this forum and this is my 1st time to use VBA....
I've looked thru the forum and I found that the someone has answered similar question before but it only has the code posted . So I can't visualize how it's gonna work w/o the file
http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_21188706.html?qid=21188706

My Problem:
I've created a userform so the user can open up the form to enter the info on the form and post on a worksheet. After that, the user hits the export button and all the info will be transferred to Access database table. My question is how to update/search the Access record by using the same or separate userform in Excel?  

Below is part of the code in my userform

Private Sub LoadData()
Dim dbmain As ADODB.Connection
Dim rcset As ADODB.Recordset
Dim sqlstr As String
Dim dbPath As String

dbPath = "C:\Documents and Settings\yuenk\Desktop\GAAP Testing\DB1.mdb"

Set dbmain = New ADODB.Connection
dbmain.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath


sqlstr = "SELECT Value " & _
        "FROM Testing " & _
        "WHERE testing.[AnalystName] ='" & Me.cboAnalystName & "';"

"I WOULD LIKE TO PUT MORE CRITERIA IN THE WHERE STATEMENT TO MAKE SURE IT ONLY RETURNS ONE VALUE BUT DON'T KNOW HOW"

Set rcset = New ADODB.Recordset
rcset.Open sqlstr, dbmain, adOpenKeyset, adLockOptimistic

Do Until rcset.EOF
With Me.LstData
.AddItem rcset.Fields(0)
.Column(1, .ListCount - 1) = rcset.Fields(1)
End With
rcset.MoveNext
Loop
ExitSub:
If Not rcset Is Nothing Then rcset.Close: Set rcset = Nothing
If Not dbmain Is Nothing Then dbmain.Close: Set dbmain = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Number & "-" & Err.Description, vbOKOnly + vbExclamation, "Error"
Resume ExitSub
End Sub

Private Sub lstData_Click()
Me.CmdExit.Enabled = Me.LstData.ListIndex > -1
End Sub

-----END CODE----
I know that I have to add more command buttons such as "Search" and "Update" later on.
This piece of code was copied and modified fromt the link above"

I can e-mail my file to you if I don't explan it clearly and  any comments are welcome.

Patrick
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Software
Question Asked By: yuen338
Solution Provided By: Kelvin81
Participating Experts: 4
Solution Grade: B
Views: 628
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by XL-Dennis

Rank: Guru

Expert Comment by XL-Dennis:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by yuen338
Author Comment by yuen338:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by zorvek

Rank: Genius

Expert Comment by zorvek:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by XL-Dennis

Rank: Guru

Expert Comment by XL-Dennis:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by yuen338
Author Comment by yuen338:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Kelvin81

Rank: Master

Expert Comment by Kelvin81:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by yuen338
Author Comment by yuen338:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by LoNeRaVeR9

Rank: Sage

Expert Comment by LoNeRaVeR9:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by yuen338
Author Comment by yuen338:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by LoNeRaVeR9

Rank: Sage

Expert Comment by LoNeRaVeR9:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by Kelvin81

Rank: Master

Accepted Solution by Kelvin81:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34