MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Feb 18th, 2002, 04:20 AM   #1
richey
New Member
 
Join Date: Feb 2002
Location: Manchester, England
Posts: 7
Default

Hi

for example, I have in Access a record with field names 'ID' 'Section' and 'frequency'
The ID is 001
The Section is Human Resources
The frequency is quarterly

How do I?

i) As the section is Human Resources - when I click a button it opens the excel document called 'Human_action_points.xls'

ii) create a new worksheet called Human_001 (i.e. the section + ID)

iii) copy the recordset values to the newly created worksheet

iv) as the frequency is quarterly - select the already created worksheet 'quarterly' - and copy the table that is there and paste it onto out newly created worksheet

iv) not allow the user to skip through other worksheets

v) after saving, anytime the user opens access and they click the 'button' on record 001 it opens the exact worksheet Human_001

I know its alot, but any help much appreciated
Thanks
richey is offline   Reply With Quote
Old Apr 17th, 2003, 11:13 AM   #2
David_UK
Board Regular
 
Join Date: Mar 2003
Location: United Kingdom
Posts: 280
Default Extractin data

Have you used MS Query before, would that help?
David_UK is offline   Reply With Quote
Old Apr 17th, 2003, 11:23 AM   #3
Nimrod
MrExcel MVP
 
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
Default

Here's some code that will allow you to see how to modify/download data from Access To Excel.

Sub UpdateRecordsQuery()
Dim Db As database
Dim Qd As QueryDef
Dim Rs As Recordset
Dim qdParmQD As QueryDef
Dim SQL As String
Dim i As Integer

' Set your database object. You may need to change the path to match
' where Microsoft Office is installed.
Set Db = _
workspaces(0).OpenDatabase("C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb")

' 1. Create a PARAMETERS clause string.
SQL = "PARAMETERS [CountryWanted] TEXT; "

' 2. Create a SELECT statement.
SQL = SQL & "SELECT DISTINCTROW * " & _
" FROM Customers" & _
" WHERE (Customers.Country =[CountryWanted]) "

' 3. Create a named QueryDef object with your SQL statement.
Set Qd = Db.CreateQueryDef("Find Customers", SQL)

' 4. Set the QueryDef object parameters.
Set qdParmQD = Db.querydefs("Find Customers")
qdParmQD("CountryWanted") = "Germany"

' 5. Execute the QueryDef.
Set Rs = qdParmQD.OpenRecordset()

' 6. Issue a MoveLast followed by a MoveFirst
Rs.MoveLast
Rs.MoveFirst

' 7. Set up a loop that will modify each record in the recordset.
For i = 1 To Rs.RecordCount
Rs.Edit
Rs("Region") = "Europe"
Rs.Update
Rs.MoveNext
Next i

' At this point, the database has been modified. The rest of this
' code displays the data on a worksheet. This is not necessary to
' complete the operation.

' 8. Collect field names.
For i = 0 To Rs.Fields.Count - 1
Sheets("Sheet1").Cells(1, i + 1).Value = Rs.Fields(i).Name
Next i
Sheets("Sheet1").Range(Sheets("Sheet1").Cells(1, 1), _
Sheets("Sheet1").Cells(1, Rs.Fields.Count)).Font.Bold = True

' 9. Issue a MoveFirst to move to the beginning of the recordset.
Rs.MoveFirst

' 10. Use CopyFromRecordset to move the data onto the worksheet
Sheets("Sheet1").Range("A2").CopyFromRecordset Rs

' 11. Select the sheet that data was written to and autofit the
' column widths.
Sheets("Sheet1").Select
Selection.CurrentRegion.Select
Selection.Columns.AutoFit

' Select cell A1.
Range("A1").Select

' 12. Clean up and delete the QueryDef that was just created. This
' removes it from the database. Then close the objects.
Db.querydefs.Delete "Find Customers"
Qd.Close
Rs.Close
Db.Close

End Sub


You may also want to check out this info from MicroSoft :http://support.microsoft.com/default.../excel/dao.asp
__________________

<MARQUEE>...........Never be afraid to try something new. Remember, amateurs built the ark, professionals built the Titanic...............The easiest thing to find is fault, don't be easy !.. --Anonymous--...</marquee>
Nimrod is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:23 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes