Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    mcalpi18 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    12

    Using command buttons to create a new record and populate several fields.

    Hello,



    I have been assigned the task of creating an extremely easy to use interface using microsoft access to record weld quality.. I have pratically no background with access but am eager to learn. I have been working on this database for over a week now and and seem to have hit a brick wall.

    I have a Master table that I would like to populate using command buttons from my form. I would like to setup command buttons so that when clicked they will create a new record and populate the fields of this record with specified values or text.

    In reviewing several forums I am led to believe that the code should be something along the lines of:

    Here is what I beleive my code should look like but I cannot get anything to work!
    Option Compare Database

    Private Sub Command24_Click()
    Master.Entry_Date.Value = Date() - I would like this to be the current date
    Master.Plant_Area = "URS" - I would like my table's (Master) Field (Plant_Area) to be given the text URS
    Master.Station = 9 - I would like my table's field (Station) to be given the value of "9".
    Master.robot = 1
    Master.weld = 1
    Master.Score = 2
    End Sub

    The part that is after the "Me." is the field of the table I wish to populate. and after the "=" is what I would the new record to populate the field with.

    But after trying this several times without success I am back to the brick wall.

    Any help or advice would be greatly appreciated!
    Sincerly Thank you,
    Matt
    Last edited by mcalpi18; 10-23-2013 at 10:01 AM. Reason: Updated Code

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Welcome to the forum.

    First you should visit Roger Carlson's site and read the tutorials. It will help you understand some basic concepts.
    http://www.rogersaccesslibrary.com/f..._topic237.html

    Next, Google "naming convention". This is important - it will save you lots of grief.
    I see by your example you have used spaces in object names and the "#" sign.
    Object names should only be letters, numbers and possibly the underscore. Do not use spaces or special characters/ punctuation.

    You really want to hard code the station, robot number, weld number and the score? Seems like they should be controls on the form.

  3. #3
    mcalpi18 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    12
    Thank very much for your feed back it has already been very useful. I was told to use command buttons so that I can lay them over a map of the facility.

  4. #4
    mcalpi18 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    12
    I have tried updating my names and code but am still having issues?

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you created a form that displays all of the Fields you want to update yet?

  6. #6
    mcalpi18 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    12
    No, I would like to only be able to view the fields in the master table to try and keep the interface as user freindly as possible.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Steve,
    I'll let you take that one. 8^)

  8. #8
    mcalpi18 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    12
    Is there an easier way to do this? I am very new to access and could use all of the help I can get... I essentially want every button to create it's own unique record...

  9. #9
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36
    I don't really understand your complete task but to add date to your tables, you will need forms. You never -ever- want users to enter information directly into the tables.

    Since you are so new to Access, my first suggestion is to read as much as you can about it, even if it is just the highlights.
    The link provided by Steve is a great place to start and here is another one:http://allenbrowne.com/casu-22.html

    I have taught myself how to use every Office program but Access is not a program you can just throw together without any understanding of how everything works together.

  10. #10
    mcalpi18 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    12
    Hello,

    my complete task is to have a form that has several command buttons on it. Each command button when clicked will create a new record in my "Master" table and populate the fields of that record with preset values or text. Each button will essentially create its own unique record using the values or text I specify for each field. I am trying to learn as much as possible but due to the time constraints and guidlines on this project, I really need to solve this specific issue before moving on in my learning.

    Thank you Again!

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I don't want to side track you from your task at hand but have you considered the data types you are using? Data types are important and you want to understand data types before you write VBA. Maybe you can try this, as an exercise.

    Dim dtCurrent as Date
    dtCurrent = Date()

    Me.Entry_Date.Value = dtCurrent

    Here you are passing the value Date() to a declared variable of the date type ... dtCurrent

    dtCurrent is simply a name/word I imagined.

    You can create an unbound field on your form and pass your variable to that field by referencing its name.

    Me.txtNewField.Value = dtCurrent


    You can adjust your new field's properties and format to show the date data type in different ways.


    Test strings can be done like this

    Dim strText as string

    strText = "Test String"

    Me.txtNewField.Value = strText

  12. #12
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36
    So in your database, you have one master table and one main form that contains only the buttons you want to code?
    Do you also have the fields you want each button to update?

    When you say "Me.Date = Date", etc, the "Me." is referring to the field on the current form. So, on the form that contains the command buttons, you will need the fields you are trying to update, even if you choose to hide them. Otherwise, Access has no idea where you want that information to go.

  13. #13
    mcalpi18 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    12
    Yes that is correct.

    Thank you! That is one of my issues! I just tried:

    Private Sub URS_S09_R01_NF_Click()
    Master.robot = 1
    End Sub

    But did not have any luck. My table name is "Master" and the field I am trying to update is "Robot". I would like to set this up so that when the button is clicked my table's field ("Robot") is given a new record and value of 1...

    1 Step Closer!! thank you!

  14. #14
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36
    So URS_S09_R01_NF is your button name?
    Following Access naming conventions, I would name them by what they do and leave out any spaces. For example, on my main form mine are cmdCreateNewOrder and cmdBeingRepair. That way, when I look at the VBA code, I know what everything is and what it does.

    I still recommend adding the fields you want to update to the main form and then hiding them from users. Then you can use the simpler Me.Station = 1 as long as your field names are correct.

  15. #15
    mcalpi18 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    12
    Yes URS_S09_R01_NF is my button name. I now believe that using a Option Group Control is the route I should follow. The issue im still having is once the button is clicked I still need it to populate all of the fields in my table... Any ideas?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Populate Radio Buttons from Database record
    By CementCarver in forum Access
    Replies: 5
    Last Post: 02-25-2013, 12:38 PM
  2. Replies: 11
    Last Post: 02-04-2013, 05:32 PM
  3. Command Buttons
    By BLD21 in forum Access
    Replies: 2
    Last Post: 05-10-2011, 06:27 AM
  4. Make command buttons unique to a record
    By timmy in forum Forms
    Replies: 26
    Last Post: 03-09-2011, 09:51 AM
  5. Command buttons
    By maintt in forum Forms
    Replies: 3
    Last Post: 08-03-2010, 09:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums