Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2007
    Posts
    70

    Unanswered: Combobox OnChange issues?

    Hi,

    I have the following VB code on the onChange event of an unbound combobox:

    Code:
    Private Sub Std_Results_Change()
        On Error GoTo Err_Std_Results_Change
    
    
    Me.CCDetails = Me.CCDetails & Me.Std_Results.Value
    
    
    Exit_Std_Results_Change:
        
        Me.Requery
        
        Exit Sub
        
    
    Err_Std_Results_Change:
        MsgBox Err.Description
      
        Resume Exit_Std_Results_Change
    
    End Sub
    It works OK but isn't doing excactly what I would like. At the moment the text enters the field (Me.CCDetails) in a long line, how can I get each additional 'OnChange' to for a new line?

    Also how can I free up the memory on the combobox? As it is the combobox stores the choises in memory so if you make a misstake and choose wrong item in combobox, delete it and rechoose it will remember the first and stick them both in CCDetails. I've tried a requery as you can see in the code but has not worked. Is this in the wrong place?

    Hope this makes sence.

    Cheers

    Owain

  2. #2
    Join Date
    Feb 2008
    Posts
    7
    HI Owain

    Try changing your statement to this:

    Me.CCDetails = vbCRLF & Me.CCDetails & Me.Std_Results.Value

    This will insert a newline before the next combo box value

    as for your second point, do you mean resetting the CC Details - the easiset way would be to ask the user toconfirm prior to storing the choice:

    e.g. if msgbox("Do you wish to store this value " & me.Std_Results.value , vbyesno,"Store Value") = vbno then
    exit sub
    endif


    HTH
    Chris

  3. #3
    Join Date
    Dec 2007
    Posts
    70
    Quote Originally Posted by Chris Walker
    HI Owain

    Try changing your statement to this:

    Me.CCDetails = vbCRLF & Me.CCDetails & Me.Std_Results.Value

    This will insert a newline before the next combo box value

    Hi Chris, Thanks for the reply. I have tried this but it just Enters a new line at the beginning of the text each time and the piece of text appears at the end of the previous text!

    I tried this and it worked so thanks for the pointer.

    Code:
    Me.CCDetails = Me.CCDetails & vbCRLF & Me.Std_Results.Value
    The second problem still remains though. The msgbox was a nice I dear but even if I close down that record and then open the next one it still remembers the info and when you enter your first combobox option you get that plus all the options you chose in the first record?

    Any other ideas?

    Cheers

  4. #4
    Join Date
    Dec 2007
    Posts
    70
    Quote Originally Posted by OB1

    Code:
    Me.CCDetails = Me.CCDetails & vbCRLF & Me.Std_Results.Value
    Sorry just need to make a slight chance to the previous code. It was this code that worked how I'd like it

    Code:
    Me.CCDetails = Me.CCDetails & Me.Std_Results.Value & vbCrLf
    Owain

  5. #5
    Join Date
    Feb 2008
    Posts
    7
    Hi Owain

    Ah.... Is the comboxbox set up to allow data entry (i.e. the Limit To List - under the combox box Data tag - set to NO) - if so I would do the following:

    1. Change the Limit To List to YES
    2. In the On Not On List put the following code:

    if msgbox("Do you wish to store this value " & me.Std_Results.value , vbyesno,"Store Value") = vbno then
    Response = acDataErrContinue
    Exit Sub
    End If

    Me.Std_Results(NewData)
    Response = acDataErrAdded


    Me.CCDetails = Me.CCDetails & vbCRLF & Me.Std_Results.Value

  6. #6
    Join Date
    Dec 2007
    Posts
    70
    Hi again,

    Thanks for all your help, I'm afraid I've been sending you on a wild goose chase!!
    So sorry. It was so simple I missed it!!!

    I had forgotten to put a Me.Requery in the OnLostFocus event in the field CCDetails!

    How embarrassing

    Works fine now,

    Cheers

  7. #7
    Join Date
    Feb 2008
    Posts
    7
    NW

    Glad you are sorted

Posting Permissions

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