473,378 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to create macros that will help in doing functions in Forms.

My database holds records related to Kids. It contains key metrics on the Kids. This data is colleced in the KidDataForm and stored in teh Kid table.

The datbase has a table to collect data on Mothers, called Mother table. Mothers can have multiple Kids. If Mother data is required, it is collected in the MotherDataForm.

The KidDataForm has a link to the MotherDataForm. That link is a control called "Mother Name". Mother Name is the primary key for the Mother table.

From time to time, a new record in the Mother table has to be added. At present, the process is cumbersome:
1) Click Button to open MotherDataForm (opens to new record, since there is currently no link).
2) Input name of Mother in MotherDataForm
3) Save the records.
4) Refresh Database
5) Return to KidDataForm
6) Select the name of the Mother, which should now appear in the "Mother" control drop-down box.
7) Go back to the MotherDataForm and update the record on the Mother.

What I want to know is HOW I can create a macro (which I would attach to a new button), that would allow me have Access automatically populate and link the tables. This is what I want to do:
1) Type name of Mother in the Mother control drop-down box. (I can do this now.)
2) Have access automatically copy that name into the Mother table as a new record and then open the MOtherDataForm on that record.

I cannot find any code (that I can understand) to do this. I would love it if someone could show me some example code and what each line is doing.
Mar 21 '13 #1
7 1406
zmbd
5,501 Expert Mod 4TB
Which version of Access are you using?

As for Macros:
You'll not find much help here for "Macros" as most of us use the VBA language to handle things like this due to the robustness of the programing environment.
Mar 21 '13 #2
Is there VBA language that would accomplish this? I sometimes (think?) I have used Visual Basic for Excel.
Mar 22 '13 #3
I found some code on a similar help website, which I think accomplishes similar to what I want to do, but I am having a very hard time making heads or tails of it. I put ' marks in front of how I am interpreting this. But - I still find it totally confusing and am not sure how I should adjust it for my database.


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSend_Click()
  2. On Error GoTo ProcError 
  3.  
  4. Dim db As DAO.Database
  5. 'What is this doing with "DAO.Database"
  6. Dim rst As DAO.Recordset
  7. 'What is this doing with "DAO.Recordset"
  8. Dim strTextData As String 
  9. strTextData = txtBox 
  10. 'I think this is making my variable StrTextData equal to what is in the text Box.  But, how does the macro know to which text box on the form I am referring?
  11. Set db = CurrentDb 
  12. 'db is the database I am talking about.
  13. Set rst = db.OpenRecordset("tblTest",dbOpenDynaset) 
  14. 'rst is the Table, which I have named tblTest in my database?
  15. rst.AddNew 
  16. 'Is this a known command to add a new record?
  17. rst!fldTest = varTextData 
  18. 'Should this actually be strTextdata?
  19. 'Is the fldTest mean that the field I want in the table is called "test"
  20. rst.Update Me!txtBox = "" 
  21. 'I don't understand this at all.
  22.  
  23. ExitProc: 'Cleanup 
  24. If Not rst Is Nothing Then rst.Close: 
  25. Set rst = Nothing 
  26. End If
  27. 'Confused.
  28.  
  29. Set db = Nothing
  30. Exit Sub
  31. 'confused
  32.  
  33. ProcError: MsgBox "Error " & Err.Number & ": " & Err.Description, _ vbCritical, "Error in procedure cmdSend_Click..." 
  34. Resume ExitProc
  35.  
  36. End Sub
Mar 22 '13 #4
ALSO: I am using Access 2010
Mar 22 '13 #5
zmbd
5,501 Expert Mod 4TB
V2010 - yea.

Now, I'm not a big fan of this; however, let's try the following for your form as I get the impression that VBA isn't something you are very comfortable.

As you have a form that you are already using for data entry for the mother's information " MotherDataForm" we're going to stick with that.

Open the child's information form in design mode.
Right click the control for the mother's name and select the properties option in the pop-up.
Select the data tab
- part way down set the limit to list to yes
- just below that is "list items edit form" click on this and select the form MotherDataForm

Save, close the forms, re-open the child's information form...
If you click the drop-arrow in the combobox for the mother's name, you'll see a faint "pencil-dialog/form" shadow, you can click that and it will take you to the motherdataform or enter a new mothers's name that is not in the list and you will be asked about editing the list information.
Either way, the motherdataform will be opened. You can add all of the mother's information; however, you will have to close it to go any further.
If you don't have a close button on the motherdataform you can right click and close.
This will bring you back to the child's information form and the new item will be there in the list.

This method has some roughness to it; so, if it isn't just exactly what you want we can work on a full blown VBA approach.

As for the code you posted... it's for a Command Button and it could be made to work; however, it isn't quite the method I would have used to get things to happen; however, it does do the job. - However, I'm going to ignore it for the moment.
Mar 22 '13 #6
Zmbd - I am so thankful for your help. Unfortunately, I had a few other "fire drills" today to handle. I am excited to test this out and see how it works. I will report back. Thank you again!!
Mar 23 '13 #7
zmbd
5,501 Expert Mod 4TB
I can really understand that - I've been having those pop-up in the lab for the past month!

I'm on a retreat tomorrow so if you post and don't hear from me please don't panic - take out your towel and the Peril Sensitive Sunglasses and one us will be along shortly. ;-)
Mar 23 '13 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Gunnar G | last post by:
Hello. I use the standard C++ string and I'm very pleased with it, but it lack some functions that I need, like reverse (reverse the string), uppercase, and a few others. Now I would like to add...
8
by: J.S. | last post by:
I was under the impression that frames could be used in Windows forms in earlier version of VB. However, in VB 2005 Express I don't see any such tool/control. Is SplitContainer used for this...
6
by: Rob Williamson | last post by:
Does anyone know whether there is a way to create folders inside the right payne when you click on Tables or Queries or Forms or Reports in the the Objects side. I have alot of queries and forms...
7
by: Steven W. Orr | last post by:
I have a table of integers and each time I look up a value from the table I want to call a function using the table entry as an index into an array whose values are the different functions. I...
4
by: SD007 | last post by:
Can anybody send me the tutorial to create menu in Oracle9i forms.
5
by: junjun | last post by:
Hi, I need some help with this question. I am writing a main functions, with MACRO and global variables, and lots of supporting functions a(), b(), c(),........z() that are called by main function...
6
by: jojoba | last post by:
Hi, I am trying to create a .net webservice such that: When a user calls the service, the server creates a System.Windows.Forms.Form and shows it on the server screen. I know this sounds...
1
by: maheshgupta0248 | last post by:
Im a newbie in C... can anyone tell me.. how are macros different from functions I know that macro is just a replacement, so type checking is not performed in macros.. are there any other...
1
by: pratvik roy | last post by:
Hi, I am pretty new to VBA. I wanted to know if there is a way to create a macro in an excel file and run the same, all in runtime? I am using C++ to dump few integer values into an excel...
1
by: Carole LeBlanc | last post by:
Can anyone out there direct me on the best way to build macros (to conduct quicker and more accurate searches, of course) for a rather large, and I might add old, Oracle database? Sincerest thanks,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.