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
0
Utf
11/18/2009 7:37:03 PM
excel.programming 6508 articles. 2 followers. Follow

1 Replies
836 Views

Similar Articles

[PageSpeed] 44

Hey Sam --

I think you are using the wrong connection string - change 
..Provider = "Microsoft.Jet.OLEDB.4.0"

to 

..Provider = "Microsoft.ACE.OLEDB.12.0"

since you are using Access 2007 file vs Access 2003 (2003 uses Jet)

Jim

"sam" wrote:

> 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
0
Utf
11/18/2009 9:41:02 PM
Reply:

Similar Artilces:

access 97 backend with 2000, 2002, and 2003 front ends
Is this possible to have the 97 users with 97 front end, 2000 users with 2000 front end, 2002 users with 2002 front end, and 2003 users with 2003 front end all linked up to an access 97 backend? We are currently planning on upgrading workstations with either 2000, 2002, 2003. the criteria for the specific version will depend on the IT department. I would like to know if we have several different office versions will it work to have access 97 as a back end?? thanks in advance jung That should work fine. Same rules as usual: make sure everyone has their own copy of the front end, preferably ...

Error: Invalid byte was found at byte index 63.
Does anyone know what this means: "Invalid byte was found at byte index 63. " If yes, please help. Apogee Apogee wrote: > Does anyone know what this means: > > "Invalid byte was found at byte index 63. " That means exactly what it says: At index 63 XML parser found a byte, which is invalid either according document's encoding or is forbidden in XML documents at all (see list of allowed in XML characters at http://www.w3.org/TR/2000/REC-xml-20001006#charsets) -- Oleg Tkachenko http://www.tkachenko.com/blog Multiconn Technologies, Israel ...

Input Excel 'Password to Open' through control in access form
Hi All, We know,Excel has prompt password to open it files. Is it possible to create a code that can supplies the excel prompt password?.So that when we open the excel file through our access control in a form, the excel files can be opened automatically.But when the excel files opened from its default icon,it will prompt a password first. ...

Trying to find out which numbers occure most often
I�m giving exams to students and want to see if the students are missin the same questions in every class. I have a simple spreadsheet tha has me enter the question number into the column each time a questio is missed. The MODE function can tell me which number is occurrin most often. However, I need to see if there is any other numbers tha are occurring often as well. Is there a command that will allow me to look at the second mos entered number? For example, if I have 5,3,3,2,3,4,3,4,1,3,4, my mod would be 3 as that�s the number that repeats the most. However, happens 3 times and that...

XCH Error 3092, OAB replication
I am getting error 3092 for OAB in Exchnage 2003 (migrated from 5.5) "Error 1129 occurred while processing a replication event. Folder: (3-8) NON_IPM_SUBTREE\OFFLINE ADDRESS BOOK\EX:/o" Tried to delete offilne addressbook and recreate but error has not stopped. Any help will be a great help on where to look to get rid of this issue. Thanks ...

Error Generating the Offlice Address Book
I have a mixed site with 3 5.5 server and 4 2003 servers. I installed 2003 SP1 a few weeks back and since then I'm having an issue generating my Offline Address Book. Here the event log messages I'm getting. Event ID 9331: OALGen encountered error 80040107 (internal ID 501023d) accessing the public folder store while generating the offline address list for address list '/'. - Default Offline Address List For more information, click http://www.microsoft.com/contentredirect.asp. Event ID 9335: OALGen encountered error 80040107 while cleaning the offline address list public ...

Excel not Access
I have designed an Access database that holds records relating to my stores audit results going back for about 5 years plus a load more information relating to these stores. This was used to produe a pack once a month, however a change in senior management means that I have got to shelve this and prodce a similar pack in Excel. The idea would be that the user could select a month or a 12 mnth date range that would produce data that could then be used to populate a number of excel templates that have been designed. Having not used excel for years I would be grateful for any suggestion...

Unexpected error message on closing an Excel file
Suddenly I am getting the following message when I try to close a workbook: "Your formula contains an invalid external reference to a worksheet. Verify that the path, workbook, and range name or cell reference are correct, and try again" The mysterious thing is that it does not happen consistently and that, after I click OK after the above message, I can still save the file. What might be the cause of this error message and can the "invalid reference" be tracked down using one of the utility add-ins such as J. Walkenbach's PUP? If it only happens when you close ...

Strange Access Denied Problem with Windows 7
I got a new computer about six months ago that came with Windows Vista Home Premium 64bit. Before that I had done all of my .NET development either on an XP Pro VM or my former XP Pro computer at home. Shortly after getting my new computer at home, I also got a license for VMWare to be able to test my software on multiple platforms and configurations. I had wrote an application originally in VB.NET that was a simple backup utility. It supports mutiple backup configurations. Any given copnfiguration would define a backup which would be a list of files to backup, a list of folders to ...

Linker Error after upgrade from VC7.1
Hello all, After upgrading a VC7.1 project to visual studio 2005, it failed to build in the release configuration with the follwoing error : 1>nafxcw.lib(winocc.obj) : error LNK2005: "public: class CWnd * __thiscall CWnd::GetDlgItem(int)const " (?GetDlgItem@CWnd@@QBEPAV1@H@Z) already defined in InstallDlg.obj The debug build works fine. The project uses MFC in a static library. Well, after doing some research, it seems that this one is tied to the fact that in a release configuration, _AFX_ENABLE_INLINES is defined, so inline functions are embedded in the .obj file. Sure there...

Help with income/expenses
Running 2003 in home page I setup income and expenses I prefer to see one whole month. Money some how shows it as 1/22/2006 through 2/20/2006 any way to fix this? Thanks Jeff ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- ...

Invalid XML error when I open customization setting
I have a problem when I try to open customization setting after I import an entity. The system errored "Invalid XML" "The XML passed to the platform is not well-formed XML". Please recommend how to resolve this problem. Thanks. ...

help with simple maths in excel
I want to do a simple arithmatic excercise in excel for my grand daughter. It is stuff like 2+2 =4 Smart me has hit a problem at the first hurdle... I need to put 2 in one cell the + in another cell and then 2 in another = in another and then she puts the answer in the next one. So the above would have 4 cells completed and she would put the answer in the 5th one. When I use the + or = sign in a cell of its own it (excel) thinks I am doing an equation, is there a way around this? I will work on the answer like if she gets it correct or wrong how I will do that...a sound or som...

Radar chart in Access 2007 report
Can you add a Radar chart to an access 2207 report? ...

HELP! Need to export hourly sales data on POS (NOT RMS)
How can I export hourly sales data across a date range? For instance, I want to show hourly sales for the month of October so I can graph it and post it in our break room. If I can't export hourly data, can I export daily sales? The built-in reports don't address this data format. This is a multi-part message in MIME format. ------=_NextPart_000_008E_01C826DC.CBC512D0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit Mark, This should work for you. Keep in mind it takes up to 5-10 minutes to load...

Need help with Auto Filter
I have a spreedsheet that is filtered in multiple columns. I am running a "Subtotal" function to count certian rows when I filter the column. My question is this. Is there a way to save or freeze the data that the subtotal function counts in a different cell. In other words I want subtotal to count everything in a particular column but I want to be able to save that number somewhere so that when I filter again with another variable I am able to still view the first subtotal to compare the two. I hope this makes sense and thanks in advance for any assistance you can provi...

adding name /creating field/query?
Hello, I can create an invoice_number field in a query using the primary field ID from the main table as invoice_number: ID but if ID say is 100, I cannot work out how to create renewal_invoice_100 Cheers Geoff Geoff We aren't there. We can't see what you're looking at. Where did "renewal_invoice_100" come from and what does it mean? Please post the SQL statement of the query you are trying to use. -- Regards Jeff Boyce www.InformationFutures.net Microsoft Office/Access MVP http://mvp.support.microsoft.com/ Microsoft IT Academy Program Mentor http://micro...

HELP! remote data not accessible msg
Hello, I have a use who is currently using a Bloomberg DDE add- in. Whenever he attempts to activate the add-in to retreive remote data, the system hangs. If I go to task manager, I then see a message stating "Remote data not accessible. To access this data Excel needs to open another program.... I have searched the knowledge base and didn't find much help. Does anyone have any ideas? I am desperate!!!! We are currently using Excel 2003 in XP Professional. TIA, Ramissah ...

Help with a simple database
I am attempting to use Excel to develop a simple database for my office. The database basically lists a variety of orders purchased from various vendors, and my goal is to categorize and sort each vendor seperately. For example: GC Group 4/24/03 7831.1 $1,000.00 Alpha 1/20/03 7003.1 $2,000.00 Chandler 5/6/03 7050.1 $345.50 Is what the main chart looks like. Now, what I'm trying to accomplish is, suppose I added Tomsen 4/20/03 7873.1 $200.00 to the very bottom, Excel would automatically create a new tab (or even worksheet, if possible) tit...

error 0x800cc0f
i installed windows xp, and i set up all my email accounts. they are all working , except one: i receive 0x800cc0f message, which states that the service has been interrupted, contact your ISP...., but this is not the case, since my internet conneciton is working fine all the account settings are correct I am having the same problem. I have to close outlook and reopen to retrieve all of my messages. Have you found a resolution yet? "Kerstin" wrote: > i installed windows xp, and i set up all my email > accounts. they are all working , except one: i receive > 0x800c...

McAfee 8.5.0i on access scan slows down MS Dynamics CRM web client
Our organization's McAfee 8.50i slows down MS Dynamics CRM v4 - on premise web client considerabley when loading forms and data. Besides completely disabling McAfee, does anyone know how to configure McAfee (or configure CRM) to ignore CRM related form and data loads. When disabling the oncaccess scan, or when disabling the scriptcan - it improves lookups from 8-9 seconds to 4-5 seconds. However, the organizatin policy is to have these enabled. What to do? We have the same behavior, and went we reported to Microsoft says that no solution has, then we buy and install Microsoft Securi...

Looking for help on timing within a function
At the facility I work, our associates use a very basic access database to sign out individual work orders on an interval of around every 12 minutes. They have asked if it would be possible to put a timer on the front page of the database to show how long they have been working on the current work order, updating each time they sing out another order. I am not very adept at access nor is the rest of our management staff. Is it possible to add this function, so they can better keep time of their work being done? Use the Form Timer event. Here is an example of how it can be done. In this ex...

error on upgrade: ID 4386
Hello, I am upgrading from DPM 2010 RC to DPM 2010 RTM, 64 bit version, on Win 2008 R2 standard. The RC is working without any issues. The upgrade scenario is supported. At the very end of the process the upgrade fails giving me the following. _____ The SQL Server installation failed because a restart was pending on this computer. Restart the computer and then start DPM Setup again. ID: 4386. Details: Unknown error (0x84be0bc2) _____ Restarting the server does not correct the issue. On the next attempt I am getting the same error message. Where to look for the pending rest...

Can anyone help ?
I have created a holiday planner for staff with in are company and i need a formula that gives us only 10% of the total number of staff are off on holiday. would be greatful if anyone could help. Hello - If you have a total somewhere (I would suggest inserting a column on your spreadsheet titled Total and then entering a "1" if the person is going to be out, then total the column of "1"s by entering "=SUM(x:y)" where x=first cell in the range, and y=last cell in the range), in a different cell, enter "=.1*z" where z equals the total of people out...

Trying to read XML file into dataset
Hello. Developing a web site in VS2005, SP1, VB, .NET 2.0, ASP.NET 2.0 on XP Pro, SP2. I eventually want to use a gridview table to view xml data, but right now i can't seem to get my xml data into a dataset so that i can use it. I have an XML file and can open it in IE. There is no XSD or XSL file to go with it. I can't seem to get the XML data into a dataset. I tried using the following code, but it just does nothing. It doesn't give an error. It just executes the code and does nothing. Dim dataSet As DataSet = New DataSet dataSet.ReadXml("...