S
sam
Hi All,
I am trying to pull some information from access database and populate some
fields in excel userform. So for example, if a user inputs his "User Id:" in
User Id Textbox, certain fields like Name, Address, ect. associtated to that
user will populate on the userform
Here is the code I have worked on so far, But it is not working
Private Sub UserId_AfterUpdate()
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:\My Documents\User_Info.accdb; Jet OLEDBatabase
Password=User1234; "
rs.Open "Loan_Presentation", cn, 1, 3, 2
Set Rng = Range("User_Id")
For Each Dn In Rng
On Error Resume Next
If Dn.Value = CLng(UserId.Value) Then
Name.Value = Dn.Next
Address.Value = Dn.Next.Next
End If
Next Dn
Application.DisplayAlerts = False
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Thanks in Advance
I am trying to pull some information from access database and populate some
fields in excel userform. So for example, if a user inputs his "User Id:" in
User Id Textbox, certain fields like Name, Address, ect. associtated to that
user will populate on the userform
Here is the code I have worked on so far, But it is not working
Private Sub UserId_AfterUpdate()
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:\My Documents\User_Info.accdb; Jet OLEDBatabase
Password=User1234; "
rs.Open "Loan_Presentation", cn, 1, 3, 2
Set Rng = Range("User_Id")
For Each Dn In Rng
On Error Resume Next
If Dn.Value = CLng(UserId.Value) Then
Name.Value = Dn.Next
Address.Value = Dn.Next.Next
End If
Next Dn
Application.DisplayAlerts = False
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Thanks in Advance