HELP: Trying to populate form fields posted on intranet from a dat

  • Thread starter Thread starter sam
  • Start date Start date
S

sam

Hi all,

I have designed a userform in excel and this form is posted on companys
local intranet site so others can user it to feed in their info,

Now, My question is: Is it possible to populate certain fields on the form
from a Database? For eg, they input their ID in the form and their other
details like their name, division etc populates automatically from the
database.

Is it possible to do this with access database? the form is on the companys
local intranet and the access database would be on some network drive or
where ever the form can pull the information from. Can this be done?

Thanks in Advance
 
First Create a reference to Active X Data object Library 2.7 via
Tools-->references-->Microsoft Active X Data Objects Library 2.7

And Then somthing like the following if you need help post back.

Sub DatabaseQuery()
Dim ConnectionString As String
Dim Recordset As ADODB.Recordset
Dim SQL As String

'Connection.udl is the best way to get your
'connection string. Open "Notepad" and save as
'"Connection.udl" Then walk through the steps
ConnectionString = ""

'You can use Access' Query builder for the
'SQL Statement you need
SQL = "SELECT * FROM tblYourTable"

Set Recordset = New ADODB.Recordset

Call Recordset.Open(SQL, ConnectionString, adOpenKeyset, adLockReadOnly,
adCmdText)

If Not Recordset.EOF Then

With UserForm1

.Textbox1.Value = Recordset.Fields(0)
End With
End If
End Sub
 
Sure, it can be done if you have authority to access the data base, you know
where the data resides on the data base and you know how to write the code
to return the data from Access to Excel.
 
Back
Top