LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default HELP Error: Trying to populate userform fields from access databas

Hi All, I have been struggling with this since long, I would appreciate if
anyone can help me with getting this done. Basically I want to pull
information from access database and populate my excel userform fields.
For eg: If I input a Student Id field I want to populate the Name and Phone
number for that student from access database, Here is the code that I have so
far, But it gives me errors.. Please guide me through this


Private Sub StudentId_AfterUpdate()

Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String

strSQL = "SELECT Name, Phone FROM Student_Info;"
Set cnt = New ADODB.Connection
With cnt
..Provider = "Microsoft.Jet.OLEDB.4.0"
..Properties("Data Source") = "C:\My Documents\Students.accdb"
..Properties("Jet OLEDB:Database Password") = "mystudents"
..Open
End With

Set rst = New ADODB.Recordset
With rst
..CursorType = adOpenKeyset
..LockType = adLockOptimistic
..Open strSQL, cnt
End With

With UserForm1
Me.Name.Value = rst.Fields(7)
Me.Phone.Value = rst.Fields(9)
End With

rst.Close
cnt.Close

End Sub

Thanks in advance
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP PLEASE: Populate certain userform fields from access database sam Excel Programming 13 November 25th 09 09:44 PM
populate some userform fields from access database sam Excel Programming 1 November 9th 09 05:35 PM
Populate userform fields from access database sam Excel Programming 1 November 7th 09 12:49 PM
HELP JOEL: auto populate certain userform fields from access datab sam Excel Programming 0 November 5th 09 07:16 PM
HELP: Populate corresponding userform text fields from access data sam Excel Programming 1 October 5th 09 08:28 PM


All times are GMT +1. The time now is 09:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"