Results 1 to 6 of 6
  1. #1
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Lock ComboBox (2003)

    The problem is here: cboAccountID = Null

    To test for Null you need : if isNull(me.cboAccountID)
    Regards
    John



  2. #2
    Lounger
    Join Date
    Apr 2002
    Location
    Salem, New Hampshire, USA
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Lock ComboBox (2003)

    Thanks for suggestion, but made no difference.
    Tried in all three triggers: OnCurrent/OnLoad/OnActivatte, still get locked cbo, does not unlock or change color.

    But thanks for the correction with the IsNull syntax. I am sure that eliminates part of the problem.

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Lock ComboBox (2003)

    Are you sure that AccountID is actually Null in new records.

    By default Number fields have a default value of 0 (unless you change the default)

    So to test this try the following

    If isnull(me.cboAccountID) then
    msgbox "null"
    else
    msgbox me.cboAccountID
    end if



    You could the Oncurrent event for the job you are trying to do.

    if not me.newrecord then
    code for old records etc
    else
    code for new records etc
    end if
    Regards
    John



  4. #4
    Lounger
    Join Date
    Apr 2002
    Location
    Salem, New Hampshire, USA
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Lock ComboBox (2003)

    You got it riight John. cboAccountID was not null.
    I had already removed default of 0 on the properties of the form, but the underlying table still had the default of 0 (dummy-me).
    The database is split, so I had to go to the backend database to make permanent changes.
    While I was in the neighborhood, I removed all the other default 0 in all the tables that I thought might cause problems.

    Once that was done your MsgBox brought up NULL, as I wanted.
    But, you also reminded me about .NewRecord which I had forgotten about. Have been away from Access for too long.

    After using the MsgBox to see if NULL, I also got the idea to look in Datasheet format vs. SingleForm, and sure enough, there was the "0" sitting in the cboAccountID field.
    I never thought to look for the 0. Great catch by you.

    Do uou see any benefits/drawbacks of using NewRecord vs. Checking for IsNull?

    The end is nearly in sight for me now, only have about 6 more "major" obstacles.
    Major to me because my first attempt at solution did not work. I will pick away one at a time.

    Thanks again for your help with this, One day I hope to return the favor.

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Lock ComboBox (2003)

    I am glad my guess was correct, and it solved your problem.

    I do not think it matters much which way you do it. I think I would use me.newrecord because it goes straight to the test you really want to perform.

    You are only interested in whether cboAccountID is null as an indicator of a new record, so why not test new record directly?
    Regards
    John



  6. #6
    Lounger
    Join Date
    Apr 2002
    Location
    Salem, New Hampshire, USA
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lock ComboBox (2003) - SOLVED

    I am using a combo box to select a Customer for an Invoice. Once the Customer has been selected, I want to make the combo box ReadOnly so that it will not be changed by mistake. Required = YES. I have set Locked=YES to the combo box. I have a background color = blue.
    I have been trying to use the following code in the cboBox to change the background to while, turn Locked OFF, only on new records.
    I have put the following programming in AfterInsert to Lock the cboBox and change color to blue so this will only be needed on new records.

    'Lock AccountID to prevent change, make color = acqua
    cboAccountID.Locked = True
    cboAccountID.BackColor = "16777164"
    ----------------------------------------------------------
    This appears to be working.

    But this is not working:
    This is the code I am working with:
    -------------------------------------------------------------------------------
    'Unlock AccountID for Data Entry, make color = white
    If cboAccountID = Null Then
    cboAccountID.Locked = False
    cboAccountID.BackColor = "-2147483643"
    End If
    ------------------------------------------
    I have tried it in the Form.Current/OnLoad/OnOpen/OnActivate but get same result on adding new record. The cboBox is blue and Locked, I cannot add a new record. That would be consistent with the object properties, but I am expecting the programming above to unlock, change color. Allow selection of Customer. Saving record (is new because cbo is empty(null), so AfterInsert will set back to blue and locked.

    I suspect I may be doing this backwards, should have normal property unlocked and white, and use OnCurrent to change to blue and locked? Could also change to Text Box vs. cboBox but no idea how to do that.

    Suggestions, please?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •