Results 1 to 9 of 9
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Setting up a default in a check box based on an after update question/help!!!

    Hi all,
    I have a combo (CboCompanyType) that selects the "Company Type" from a query. I also have a check box on that called "Primary" in that query.
    I am having problems coming up with a code as to when i select a "CompanyType" from the dropdown, i want it to see if it all ready has a primary type
    in the query where "CompanyID=" CompanyID
    If it does, then msgbox "Primary all ready exist, would you like to replace?"
    If yes, then remove the record that all ready set to primary and make this record primary.
    If no, then cancel
    If it doesnt have a Primary value yet in the query then
    Call Primary Click
    Something to this efect, not even sure how to say this clearly?
    Basically looking to make a check box for a Primary but only allow one per CompanyID if
    this make sense?



    Primary_OnClick()
    If Primary = 0 then
    MsgBox "Would you like to set as Primary?"
    'If Yes then set value to check box = -1
    'If No then cancel=True

    CboCompanyType_AfterUpDate()
    'Check to see if table/Query all ready has a primary where "CompanyID=" CompanyID
    If Primary = -1, then


    MsgBox "Primary all ready exist for this company! Would you like to replace?"
    'Yes then set Primary Value to = 0 for the one that is all ready checked
    'and set primary value for this record to =-1
    'If no, then cancel = true

    Thanks
    Dave

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    No it really doesn't make sense and is not helped by your vague terminology
    What exactly is the point of what you want to do?

    Are you trying to change a primary key field using code?
    Are you talking about a primary key field or a yes/no field (badly) named Primary?
    A Yes/No datatype would NEVER be used as the primary key field
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi, the chkbox nane is primary, it’s not primary key...

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    For all purposes let’s make “primary” default. Seeking to make one record a default with in a query where the companyid is = to the companyid in the combo

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    You really need to change the name of that checkbox
    There is no such thing as a default record.
    Nor can you refer to a default yes/no field or checkbox control.
    Perhaps you mean default value? I really don't know

    Hopefully someone else will have more idea but I have no clue what you mean.
    Sorry. I will drop out now
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Just skip it, not worth the name of the field! Have you ever been to PayPal and had multiple addresses when it asked you if you want to make this address the default?

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Now that finally makes sense.....
    The easiest way is to set all records for that yes/no field to false using an update query or sql equivalent .
    Then set the required record as true with a second query/sql filtered to the specific record based on its primary key field.

    Hope that makes sense to you. Good luck
    Last edited by isladogs; 04-05-2019 at 11:25 AM. Reason: Typo. See to set.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thank you very much

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    You're welcome. Glad we got past the initial confusion.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 2
    Last Post: 02-12-2019, 12:49 PM
  2. Replies: 5
    Last Post: 05-16-2018, 01:04 PM
  3. Replies: 2
    Last Post: 06-25-2015, 11:42 AM
  4. Replies: 5
    Last Post: 04-08-2013, 09:04 AM
  5. Replies: 2
    Last Post: 08-05-2011, 04:41 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