Results 1 to 15 of 15
  1. #1
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159

    Set record source of a subform combo filter to null when adding new record

    Hi all,

    I have a form with a subform.

    The subform has combo box filters which I use to filter records on the subform.

    However, I want to clear them when the user clicks add new record.

    Thus far, I have come up with the following code - but it keeps saying "Object does not support this property or method"

    Here is my code

    Private Sub addNewRecord_Click()

    On Error GoTo Err_addNewRecord_Click

    Me![su_file subform].Form.cboBox.RecordSource = " "

    DoCmd.GoToRecord , , acNewRec


    Exit_addNewRecord_Click:
    Exit Sub

    Err_addNewRecord_Click:
    MsgBox Err.Description

    Resume Exit_addNewRecord_Click

    End Sub


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    A combo doesn't have that property. I suspect you want the .Value property.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    try:

    Code:
    Private Sub addNewRecord_Click()
    
    On Error GoTo Err_addNewRecord_Click
    
    Me![su_file subform].Form.cboBox.RowSource = " "
    
    DoCmd.GoToRecord , , acNewRec
    
    
    Exit_addNewRecord_Click:
    Exit Sub
    
    Err_addNewRecord_Click:
    MsgBox Err.Description
    
    Resume Exit_addNewRecord_Click
    
    End Sub
    I might suggest however you may want to just hide it instead as if the user click on it whilst in that state it will display an error as " " is an invalid rowsource.

  4. #4
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    I used the .Value property and it worked, sort of - but when you click on it the values from the records, previous to clicking add new records are still there and very much selectable. I guess the user won't know they are there unless they click on them - which they might - but then they might get confused.

  5. #5
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Well if you just dont want the user to be able to select them, this nulls the current value and then locks the control preventing further user input:

    Code:
    Private Sub addNewRecord_Click()  On Error GoTo Err_addNewRecord_Click  Me![su_file subform].Form.cboBox.value = null
    Me![su_file subform].Form.cboBox.locked = true  DoCmd.GoToRecord , , acNewRec   Exit_addNewRecord_Click: Exit Sub  Err_addNewRecord_Click: MsgBox Err.Description  Resume Exit_addNewRecord_Click  End Sub

  6. #6
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    Hey thanks r_badger - that works but kind of kills my combobox completely.

    Ah well, sure will just hide it and hope they won't notice! ;-)

  7. #7
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Check the other post I made above, it nulls the current value and then prevents input

  8. #8
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    Ahhhh........the control is completely locked and it doesn't work anymore. I can see the value but can't select...........grrrrrrrr.......

    sorry a bit of premature panicking there. I realised it's simply a matter of unlocking in the property sheet.

  9. #9
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    That's the idea that the control is completely locked........

    What exactly are you trying to achieve/prevent?

  10. #10
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    Lol. Sorry R badger, I just got a little emotional there.

    I just want to clear it momentarily when someone goes to add a new record. I don't want to see the previous values and I don't want to be able to select them - but I may want to select them after that if I decide to go scrolling through my records.

    Ah, cheers. I'll just set the values to " " and hope they won't notice - I don't think it's the end of the world really.

    Thanks.

  11. #11
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    Thanks for the lesson though - I may well use this code again. cheers!

  12. #12
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    There is a way round your problem, goto the forms afterinsert event and then add

    Code:
    Me![su_file subform].Form.cboBox.locked=false
    Last edited by R_Badger; 05-24-2012 at 09:38 AM. Reason: I originally wrote afterupdate instead of afterinsert

  13. #13
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    Quote Originally Posted by R_Badger View Post
    There is a way round your problem, goto the forms afterinsert event and then add

    Code:
    Me![su_file subform].Form.cboBox.locked=false
    Ah ha, I thought there may be something like that!

    The sun was shining outside yesterday and I was anxious to get out the door!

    Please excuse my overly emotional outburst.

    Thanks R_Badger - you are a helpful soul indeed!

    Rich.

  14. #14
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    I know your pain, I was suffering the same yesterday and funnily enough this morning too!

  15. #15
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    Lol. Me too.

    Though I'd imagine the weather yonder is generally better than the wesht of Ireland!

    It really is a treasured occasion here - and one which you must take full advantage of!

    Fine summer weather may only last as long as the day that's in it.

    Better stop procrastinating now as I have to present my wonderful Access project later.

    Really, couldn't have done it half so quickly without the help of people like you on this forum.

    I haven't met so many helpful people since I did the camino in Spain a few years ago.

    Ahhh.......I perhaps talk to much, no? ;-)

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

Similar Threads

  1. Replies: 6
    Last Post: 05-05-2012, 08:43 AM
  2. Replies: 16
    Last Post: 01-16-2012, 09:43 AM
  3. Replies: 2
    Last Post: 01-03-2012, 06:54 PM
  4. Replies: 2
    Last Post: 12-07-2011, 02:51 AM
  5. execute code on subform without adding a record
    By markjkubicki in forum Forms
    Replies: 5
    Last Post: 10-13-2011, 12:23 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