Results 1 to 4 of 4
  1. #1
    moneil is offline Novice
    Windows 10 Access 2013
    Join Date
    Dec 2015
    Posts
    5

    Adding a command button to open different form to add a new record.

    I'm building a database for a food bank to manage food drives. It has a table titled Organization Table with an auto numberprimary key, OrgID. This table contains informationabout the organization and has an one-to-many relationship toanother table which tracks events and collections.
    I created three forms based on the Organization Table:




    1. Organization Detail form, which includes all the fields fromthe Organization Table, in form view.
    2. Organization Datasheet form, which includes only the OrgID and organization name, in datasheet view.
    3. Organization List form, which is a blank form with theOrganization Datasheet form inserted as a subform.

    The Organization List form (with the datasheet view subform)is the main form that people will work with. When one clicks on the OrgID of a record in the datasheet subfor thatrecord pops up in form view … it took me forever to figure that out but itworks well now … so a record (with all its fields) can be viewed or edited withease.
    In the header of the Organization List from I will put a lookupbox and some control buttons.
    If a new organization needs to be added I want a button that will open a blank Organization Detail form, so the new record can be added there. Every which way I’ve tried to do this thebutton goes to a new line in the datasheet subform, I can’t figure out how tohave it open a blank detail from.
    Any suggestions will be greatly appreciated!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Have you looked at the Split form object? It allows simultaneous display of datasheet and single record on one form. Click record in datasheet section and corresponding data displays in single record section.

    Otherwise, post code you have attempted.
    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
    moneil is offline Novice
    Windows 10 Access 2013
    Join Date
    Dec 2015
    Posts
    5
    Thank you for your reply, and the split form suggestion,though that is what I’m trying to get away from.
    The database main view was originally a split form but Iwanted to have more screen space for the individual detail form view.
    I created two forms based on the Organization table: One is in “form view” and has all the fieldsfrom the table; the other is in “datasheet view” and contains only the ID,name, branch name, and contact person fields from the table.
    There is a third blank form, which is the main userinterface form, with a header. Thedatasheet view from is inserted into it as a sub form and one can scroll up anddown it looking for the record they need. Then you can click on the ID field of the record and the detail singlefrom pops up for review or editing. There is a command button on the detail form to close it when finished,and one returns to the datasheet view.
    At the top in the header of the “primary form” I want to adda command button to create a new record, for when a new organization needs tobe added. My first approach was to usethe command button wizard (I have Access 2007) for adding a new record, andthis is the resulting code:
    Nothing happens, literally. I’m not too bright about these things but it occurred to me that thereis nothing which connects this control to a data source, as it is sitting on a formthat contains only a sub form.
    I tried a couple of “codes” (that is what is called SQL?, Iam very much in the learning stage) that I found on the internet, but at mostthey directed the cursor to the “(New)” line on the datasheet. Unfortunately I don’t have copies of what I’vetried … I’m learning to start cataloging these with a descriptive note, as alearning exercise.
    I would like a button on the “main form” that when clickedwill open a blank Organization form in form view and a new record can be added,which when the form is closed the new record will be added to the Organizationtable, which would also include it in the datasheet form view. I’m guessing I need “add a new record” codewhich also includes code to open a blank form view form where the record willbe added. For the moment I can simplyadd a new record on the (New) line of the datasheet sub form, then click the IDfield to pull up detail from to finish completing the record.
    Attached Thumbnails Attached Thumbnails code screen shot.jpg  

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    The code you posted is neither SQL nor VBA, it is an Access macro. It does exactly what it is designed to do - go to new record row. If you want to open another form then use command to do that. Set the DataMode argument to 'Add'.
    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. Replies: 13
    Last Post: 06-20-2018, 03:18 AM
  2. Adding a record will add a command button
    By NickWren in forum Programming
    Replies: 8
    Last Post: 04-04-2017, 07:11 PM
  3. Replies: 5
    Last Post: 10-18-2016, 06:00 AM
  4. Replies: 9
    Last Post: 09-17-2013, 11:08 PM
  5. Replies: 2
    Last Post: 05-11-2012, 11: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