Results 1 to 4 of 4
  1. #1
    Naveen Marapaka is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    33

    VBA code for creating new record

    Hi dears,



    I have a small issue with creating new record.


    like i have
    2 Tables: Emp_Data, Over_Time, Emp_No is the primary key in both tables.
    2 forms, Main_form, Sub_form

    Main form has fields, Emp_no, Emp_Name and a search field to search records by any one of 2 fields

    and Subform is DataSheet mode to display records of selected field(can be any of above 2 as base to search).
    Corresponding display records will be are Emp_no, Emp_name, Emp Branch,Over_TimeDuty_on

    now my problem is I want to add a new record in subform datasheet of existing records for selected Employee.


    To be more clear what i require:

    In Main form - search by Emp_no and enter in textbox as 0025 then
    in subform DataSheet- 4 records of selected employee will display with different Over_TimeDuty_on
    now I want to enter new record in Datasheet as 5th entry.

    but I have to manually enter Emp_no, Emp_name,Emp Branch, Over_TimeDuty_on details in the 5th record.

    It should be autofilled all the details of selected Employee except Over_TimeDuty_on field in the new record.

    pls help here.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Why enter Emp_name, Emp_Branch in the subform record? This is duplication of data. Only the Emp_No needs to be in the subform record. The name and branch data can always be retrieved in query by joining tables.

    Why is Emp_no primary key in BOTH tables? Is this a one-to-one or one-to-many relationship? If one-to-many then it cannot be primary in BOTH tables, must be foreign in Over_Time.

    If the Emp_no is primary key/foreign key then should not have to enter into the subform. Master/Child links properties of the subform container control should automatically enter the Emp_no in the subform record. http://office.microsoft.com/en-us/ac...010098674.aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Naveen Marapaka is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    33
    Hi dear thanks for the reply.

    Yes, Emp_No is foreign key, here.

    I am not only displaying records in subform as spreadsheet, but also need to edit if any changes to be done in runtime itself, so I changed Subform field of Overtime field locked as no.

    the only issue i am facing is one new record to enter in spreadsheet for the same employee!
    for this i want, what could be query to enter new record for the selected employee,

    pls help

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    I don't understand. If this is a form/subform arrangement with Master/Child links of the subform container control set to the EmpID PK/FK fields, then entry of new record in subform for the employee should be simple and not require code.

    Want to provide db for analysis? Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Creating 'Common' VBA code
    By Nevsky78 in forum Programming
    Replies: 4
    Last Post: 06-18-2012, 02:07 AM
  2. Replies: 1
    Last Post: 04-24-2012, 02:36 PM
  3. InStr and Mid code creating type mismatch
    By sephiroth2906 in forum Programming
    Replies: 6
    Last Post: 09-15-2011, 10:59 AM
  4. Creating unique record from record and field data
    By arthurpenske in forum Access
    Replies: 3
    Last Post: 08-24-2011, 06:11 PM
  5. Creating Query from Code, Concatenate fields
    By eww in forum Programming
    Replies: 5
    Last Post: 07-18-2011, 02:19 PM

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