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=21188706My 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;Da
ta 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