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 PLEASE HELP with populating userform fields from access database

Hi All,

I have an excel userform which is connected to access database, I want to
auto populate certain fields based on what I input in one textbox.

For eg: If I input Students Id, I want Students name and students phone to
populate in the userform.

So far I have got the form to populate the fields from the database, BUT it
only populates the first entry from the database.
No matter what I put in the student ID textbox it always populates detailf
form the first row only.

Here is the code I have so far.

Private Sub StudentNo_AfterUpdate()

Dim cnt As Object, rst As Object, strSQL As String

Set cnt = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")

strSQL = "SELECT Student_Name, Student_Phone FROM Student_Table WHERE
Student_No = " & Me.StudentNo.Value

cnt.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=C:\Documents\Students_DB.accdb; Jet OLEDB:Database
Password=mystudents; "

rst.Open "Student_Table", cnt, 1, 3, 2

Me.StudentName.Value = rst.Fields(7)
Me.StudentPhone.Value = rst.Fields(9)

Set rst = Nothing
Set cnt = Nothing

End Sub

Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default PLEASE HELP with populating userform fields from access database

Try this

rst.Open strSQL ,cnt, 1, 3, 2


"sam" wrote:

Hi All,

I have an excel userform which is connected to access database, I want to
auto populate certain fields based on what I input in one textbox.

For eg: If I input Students Id, I want Students name and students phone to
populate in the userform.

So far I have got the form to populate the fields from the database, BUT it
only populates the first entry from the database.
No matter what I put in the student ID textbox it always populates detailf
form the first row only.

Here is the code I have so far.

Private Sub StudentNo_AfterUpdate()

Dim cnt As Object, rst As Object, strSQL As String

Set cnt = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")

strSQL = "SELECT Student_Name, Student_Phone FROM Student_Table WHERE
Student_No = " & Me.StudentNo.Value

cnt.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=C:\Documents\Students_DB.accdb; Jet OLEDB:Database
Password=mystudents; "

rst.Open "Student_Table", cnt, 1, 3, 2

Me.StudentName.Value = rst.Fields(7)
Me.StudentPhone.Value = rst.Fields(9)

Set rst = Nothing
Set cnt = Nothing

End Sub

Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default PLEASE HELP with populating userform fields from access databa

Thanks for helping mike,

When i change it to "rst.Open strSQL ,cnt, 1, 3, 2"

I get an error: "Syntax error in FROM clause"
on the new line "rst.Open strSQL ,cnt, 1, 3, 2"


"Mike" wrote:

Try this

rst.Open strSQL ,cnt, 1, 3, 2


"sam" wrote:

Hi All,

I have an excel userform which is connected to access database, I want to
auto populate certain fields based on what I input in one textbox.

For eg: If I input Students Id, I want Students name and students phone to
populate in the userform.

So far I have got the form to populate the fields from the database, BUT it
only populates the first entry from the database.
No matter what I put in the student ID textbox it always populates detailf
form the first row only.

Here is the code I have so far.

Private Sub StudentNo_AfterUpdate()

Dim cnt As Object, rst As Object, strSQL As String

Set cnt = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")

strSQL = "SELECT Student_Name, Student_Phone FROM Student_Table WHERE
Student_No = " & Me.StudentNo.Value

cnt.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=C:\Documents\Students_DB.accdb; Jet OLEDB:Database
Password=mystudents; "

rst.Open "Student_Table", cnt, 1, 3, 2

Me.StudentName.Value = rst.Fields(7)
Me.StudentPhone.Value = rst.Fields(9)

Set rst = Nothing
Set cnt = Nothing

End Sub

Thanks in advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default PLEASE HELP with populating userform fields from access databa

Some problem in strSQL: what's in there ?

Tim

"sam" wrote in message
...
Thanks for helping mike,

When i change it to "rst.Open strSQL ,cnt, 1, 3, 2"

I get an error: "Syntax error in FROM clause"
on the new line "rst.Open strSQL ,cnt, 1, 3, 2"


"Mike" wrote:

Try this

rst.Open strSQL ,cnt, 1, 3, 2


"sam" wrote:

Hi All,

I have an excel userform which is connected to access database, I want
to
auto populate certain fields based on what I input in one textbox.

For eg: If I input Students Id, I want Students name and students phone
to
populate in the userform.

So far I have got the form to populate the fields from the database,
BUT it
only populates the first entry from the database.
No matter what I put in the student ID textbox it always populates
detailf
form the first row only.

Here is the code I have so far.

Private Sub StudentNo_AfterUpdate()

Dim cnt As Object, rst As Object, strSQL As String

Set cnt = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")

strSQL = "SELECT Student_Name, Student_Phone FROM Student_Table WHERE
Student_No = " & Me.StudentNo.Value

cnt.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=C:\Documents\Students_DB.accdb; Jet OLEDB:Database
Password=mystudents; "

rst.Open "Student_Table", cnt, 1, 3, 2

Me.StudentName.Value = rst.Fields(7)
Me.StudentPhone.Value = rst.Fields(9)

Set rst = Nothing
Set cnt = Nothing

End Sub

Thanks in advance



  #5   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default PLEASE HELP with populating userform fields from access databa

Hey Tim,

Heres the code:

Private Sub StudentNo_AfterUpdate()

Dim cnt As Object, rst As Object, strSQL As String

Set cnt = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")

strSQL = "SELECT Student_Name, Student_Phone FROM Student_Table WHERE
Student_No = " & Me.StudentNo.Value

cnt.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=C:\Documents\Students_DB.accdb; Jet OLEDB:Database
Password=mystudents; "

rst.Open "Student_Table", cnt, 1, 3, 2

Me.StudentName.Value = rst.Fields(7)
Me.StudentPhone.Value = rst.Fields(9)

Set rst = Nothing
Set cnt = Nothing


"Tim Williams" wrote:

Some problem in strSQL: what's in there ?

Tim

"sam" wrote in message
...
Thanks for helping mike,

When i change it to "rst.Open strSQL ,cnt, 1, 3, 2"

I get an error: "Syntax error in FROM clause"
on the new line "rst.Open strSQL ,cnt, 1, 3, 2"


"Mike" wrote:

Try this

rst.Open strSQL ,cnt, 1, 3, 2


"sam" wrote:

Hi All,

I have an excel userform which is connected to access database, I want
to
auto populate certain fields based on what I input in one textbox.

For eg: If I input Students Id, I want Students name and students phone
to
populate in the userform.

So far I have got the form to populate the fields from the database,
BUT it
only populates the first entry from the database.
No matter what I put in the student ID textbox it always populates
detailf
form the first row only.

Here is the code I have so far.

Private Sub StudentNo_AfterUpdate()

Dim cnt As Object, rst As Object, strSQL As String

Set cnt = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")

strSQL = "SELECT Student_Name, Student_Phone FROM Student_Table WHERE
Student_No = " & Me.StudentNo.Value

cnt.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=C:\Documents\Students_DB.accdb; Jet OLEDB:Database
Password=mystudents; "

rst.Open "Student_Table", cnt, 1, 3, 2

Me.StudentName.Value = rst.Fields(7)
Me.StudentPhone.Value = rst.Fields(9)

Set rst = Nothing
Set cnt = Nothing

End Sub

Thanks in advance



.



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
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
Data Not populating in Access database from excel form sam Excel Programming 1 July 8th 09 06:26 PM
Error while populating a combobox from Access database shivboy[_13_] Excel Programming 1 June 29th 06 11:04 AM


All times are GMT +1. The time now is 11:23 AM.

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"