Results 1 to 4 of 4
  1. #1
    kevinnice is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    10

    Beginner - basic question

    Access 2007


    In a form,In VBA code I want to set Text30 to a field from a table
    tablename: agents
    key: agentID
    name: agent_name

    In essence : Text30.value= agent_name where agentID=2

    Can someone please show me the syntax for this?

    Thank you

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Can you provide a little more information on what tables are involved in your database and on what table the form is based. I am guessing that you do not need any VBA code, but I cannot say for sure without further info.

  3. #3
    kevinnice is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    10
    Yes, I simplified the question hoping for a simple answer!
    Here it is: I have a DB with 9 tables.
    On this particular form I use data from the table BOOKINGS.
    I want to show the total bookings by agent, of which there are 7.
    My form has 7 text boxes for the agent names and 7 more text boxes for the amounts.
    I can calculate the amounts using code - that's working.
    But I now have 7 agents codes from the bookings table and I want to display their names from the agents table.
    So text30 will display agent_name 1
    text31 will display agent_name 2
    and so on.
    The two tables are linked by agentID

    I am learning how to code VBA, so I 'd prefer an answer in that form. But any answer will be much appreciated.

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Actually it sounds like a query will give you the data more efficiently & more simply than using VBA. You would just base the form on the query.

    I have no clue what your table structure looks like, but something along these lines will give you the agent name and the sum of their bookings.
    SELECT agentID, agentname, sum(bookingamount)
    FROM tblAgent INNER JOIN tblBooking ON tblAgent.agentID=tblBooking.agentID
    GROUP BY agentID

    You could also use a combo box on your form tied to the agentID in order to display the agent name or you could use a Dlookup() function to get the name. You could also use the DSum() function to do the summing for you.

    With respect to VBA, I'm not sure from what event the code should be triggered.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Possible Access Question (total beginner)
    By SRobertson in forum Access
    Replies: 1
    Last Post: 01-12-2012, 06:01 PM
  2. Beginner-Importing excel table question
    By simmonsmtb in forum Import/Export Data
    Replies: 3
    Last Post: 03-07-2011, 11:55 AM
  3. Relational Structure - Beginner Question
    By CrazyFileMaker in forum Access
    Replies: 2
    Last Post: 01-02-2011, 11:28 PM
  4. Really basic question
    By jimlaw in forum Forms
    Replies: 1
    Last Post: 07-27-2009, 07:20 AM
  5. Basic Question
    By chris11590 in forum Forms
    Replies: 0
    Last Post: 08-04-2008, 05:57 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