Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default HELP JOEL: auto populate certain userform fields from access datab

Here is what I have so far for getting fields autopopulate based on what I
put in Roll Number field... What I want it to do is.. On excel userform..
when I input the Student Roll Number, I want certain other fields like,
Student name, Subjects taken to auto populate from an access database,, and
all this details are in access database. Hope you can help me with this.

Private Sub StudentId_AfterUpdate()

'1) Open a connection to provide a path from the excel application to
'the database. The connection could be over an internet or on a PC just
'indicating where the file is located

Dim r As Long
Dim cn As Object
Dim rs As Object

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")


cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=C:\Documents\Students.accdb"

'2) Open a recordset which is a set of instructions of what data you
'want returned. This includes a SQL (Script Query Language).

rs.Open "Loan_Presentation", cn, 1, 3, 2

With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
"ODBC;DSN=MS Access
Database;DBQ=C:Documents\Students.accdb;DefaultDir =C:\Documents\" _
), Array( _
";DriverId=25;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;;UID=admin ;" _
)), Destination:=Range("$A$1")).QueryTable
.CommandText = Array( _
"SELECT Students.Roll_No, Students.Name" & "FROM
`C:\DOCUMENTS\Students.accdb`.Students Students" _
& "WHERE Students.Roll_No = Roll_No.value")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_Query_from_MS_Access_Database"
.Refresh BackgroundQuery:=False
End With
End Sub


rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

End Sub

Reply
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
HELP: Populate corresponding userform text fields from access data sam Excel Programming 1 October 5th 09 08:28 PM
Auto populate fields Dianne Excel Discussion (Misc queries) 1 September 4th 08 01:36 PM
Auto Populate fields Mark Excel Programming 1 September 15th 05 10:23 PM
Auto populate fields Mark Excel Discussion (Misc queries) 1 September 15th 05 08:45 PM


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

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

About Us

"It's about Microsoft Excel"