Results 1 to 10 of 10
  1. #1
    Behedwin is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    61

    Question How to setup buttons with differnt commands?

    Hi

    Here is a link to my test project: https://1drv.ms/u/s!AnrRbil63rR_x0zxxMXkT7jVvwRY
    I hope someone are willing to help me with two things.

    If you open the form called Staff Profile Form
    It contains the data from table staff profile and data from contract information.

    I like how the subform is displayed in my form.
    However i want my users to only be able to add data to the subform by opening a new form window and filling out data in a form.
    And i also want my users to delete a row by selecting it and then pressing a button.

    How can i make my subform view look more like a plain listbox and how can i fix so users can delete rows in the subform?




    edit:
    apparently my link above does not work.
    i have uploaded the file here in a zip.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I tried to download file and it fails. Follow instructions at bottom of my post to attach file to post.

    For opening a form filtered to a specific record, review http://allenbrowne.com/ser-62.html.

    A record can be deleted by selecting it and pressing Delete key on the keyboard.
    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
    Behedwin is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    61
    dammit, i have attatched the same file here now.

    thanks for letting me know.

    Attachment 30973

  4. #4
    Behedwin is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    61
    Is there no solution to this?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    There are tons of solutions. Depends on what you want to do. Keep in mind, the more 'user friendly' the more code.

    For a start, to open Contract form to a new record row and populate the StaffID foreign key, consider the following.

    Rename the subform container control to ctrContracts.

    Code for the buttons:
    Code:
    Private Sub Command35_Click()
    If Me.Dirty Then Me.Dirty = False
    DoCmd.OpenForm "Contract Information Subform", , , , acFormAdd, acDialog, Me.StaffID
    Me.ctrContracts.Requery
    End Sub
    
    Private Sub Command57_Click()
    CurrentDb.Execute "DELETE FROM [Contract Information] WHERE ContractID = " & Me.ctrContracts!ContractID
    Me.ctrContracts.Requery
    End Sub
    Code behind subform:
    Code:
    Private Sub Form_Load()
    If Not IsNull(Me.OpenArgs) Then
        Me.Cycle = 1
        Me!StaffID = Me.OpenArgs
    End If
    End Sub
    If you don't want users to edit in a form, then set the form properties AllowAdditions and AllowDeletions and AllowEdits to No. If you don't want a form then use a listbox and modify code.
    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.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Here is another solution or two. As June said, the more 'user friendly' the more code.

    I firstremoved ALL spaces in all names. You said you want to have the sub form look like a list box. Easiest way is to use a List Box...

    I have never liked using a form in datasheet view. You lose access to the header/footer and control of the controls on the form.
    I also don't like to use tables as form record sources - I prefer to use a saved query.


    But play around with this. You really need to understand how things work. I created a new form for the data entry because you wanted to lock down the subform.
    A couple of place the code gets tricky because I am reusing forms....


    You'll see lots of similarities in June's code/propertied and mine.....


    Remember, these are just examples of what could be done......
    Attached Files Attached Files

  7. #7
    Behedwin is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    61
    Thank you both.
    This is a big help.

    Ill start looking at this and try to recreate it in a new file so i learn something from it.

    For some reason the datasheet view was not even availible in your file Ssanfu?
    Did you remove it some how?

  8. #8
    Behedwin is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    61
    I can not understand why i cant recreate what you did.

    I started out on a new file
    My first goal was to create the listbox to show the values from one table that are connected to the other table.

    So in this example i have a staff profile table and a log table.

    In the staff profile table we have name, adress etc.
    in the log table we have start date, end date, reason and comments

    I want a form that display the log table data that are connected to the specific profile.
    displayed in a listbox

    you made that work in your file
    but for some reason i can not get it to work in my own example.
    i want to be able to create it myself... but i can not see what i am missing.

    please help

    Attachment 30999

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I only have Access 2010 and am unable to open your db.
    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.

  10. #10
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Same as June - can't open the dB. You need to save it in an earlier format..... 2010/2007

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

Similar Threads

  1. Replies: 2
    Last Post: 04-22-2017, 04:31 PM
  2. Printing Commands Buttons
    By GCLIFTON in forum Access
    Replies: 4
    Last Post: 06-09-2016, 10:07 AM
  3. Replies: 4
    Last Post: 03-12-2015, 08:24 AM
  4. Replies: 2
    Last Post: 01-06-2014, 04:22 PM
  5. Replies: 1
    Last Post: 09-21-2012, 03:31 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