Results 1 to 5 of 5
  1. #1
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239

    Store combobox value

    Hi,

    I have a subform created from joined table, with Combobox to link records to master form. Subform is designed without record selectors or navigation buttons, and is set to continuous form.

    I have a code, where you can delete joined record for master form simply by deleting Combobox. When you delete Combobox text value, user just clicks on another field, and Msgbox for deleting records appears.

    If user presses YES on Msgbox, record from joined table is deleted....

    Now I want to enter same Combobox text value, which was in It before, IF User clicks NO in Msgbox !

    Here's code (red colour is where things get wrong):

    Code:
    Private Sub Combo5_AfterUpdate()
    Dim strMessage As String
        Dim intResponse As Integer
        Dim cmb As String
        
        On Error GoTo ErrorHandler
        
        ' Display the custom dialog box.
        strMessage = "Would you like to delete this record?"
        cmb = Combo5.Text
        
        ' Check the response.
        If IsNull(Combo5) Then
         intResponse = MsgBox(strMessage, vbYesNo + _
            vbQuestion, _
            "Continue delete?")
          End If
         
        If intResponse = vbYes Then
          DoCmd.SetWarnings False
          DoCmd.RunCommand acCmdDeleteRecord
          DoCmd.SetWarnings True
        Else
            Cancel = True
            Me.Combo5.Value = cmb
        End If
        
        Exit Sub
        
    ErrorHandler:
        MsgBox "Error #: " & Err.Number & vbCrLf & _
            vbCrLf & Err.Description
    End Sub
    How can I store this Combobox value and then call It, in another Event or what ?

    P.S.:

    Check attached sample. Open tblName, and there you'll see subform. Delete "Kennedy" from combobox, and click on upper combobox. Msgbox will open - on YES it will delete record, on NO I want "Kennedy" back in Combobox.

    Thanks for all help in advance !!
    Attached Files Attached Files

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    the .text property is only available if the control has the focus - all you need is

    cmb = Combo5

    but your code would be generating errors so you should know that already

    and me and value is the default so all you need is

    Combo5 = cmb

    although you can write it out in full if you want

  3. #3
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    Thanks for response, but this produces errors. Any other suggestions ?
    Code:
    Private Sub Combo5_AfterUpdate()
    Dim strMessage As String
        Dim intResponse As Integer
        Dim cmb As String
        
        On Error GoTo ErrorHandler
        
        ' Display the custom dialog box.
        strMessage = "Would you like to delete this record?"
        cmb = Combo5
        
        ' Check the response.
        If IsNull(Combo5) Then
         intResponse = MsgBox(strMessage, vbYesNo + _
            vbQuestion, _
            "Continue delete?")
          End If
         
        If intResponse = vbYes Then
          DoCmd.SetWarnings False
          DoCmd.RunCommand acCmdDeleteRecord
          DoCmd.SetWarnings True
        Else
            Cancel = True
            Combo5 = cmb
        End If
        
        Exit Sub
        
    ErrorHandler:
        MsgBox "Error #: " & Err.Number & vbCrLf & _
            vbCrLf & Err.Description
    End Sub

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    but this produces errors
    the reported error is a big clue about what is wrong - so what are the errors generated?

  5. #5
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    This error is generated. You can also check in attached sample.

    Error#:94 Invalid use of null
    I tried with changing declared "cmb" variable to Variant. Error dissapeared, but when you click NO in Msgbox for deleting record, Combobox doesn't get It's previous text value back. I reckon this combo value has to be somehow called from another event, AfterUpdate event get's value after user allready empties Combo value ?
    Attached Files Attached Files

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

Similar Threads

  1. Replies: 1
    Last Post: 01-16-2015, 09:28 AM
  2. Replies: 9
    Last Post: 04-01-2014, 05:06 PM
  3. Replies: 1
    Last Post: 09-06-2011, 01:47 PM
  4. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  5. Replies: 0
    Last Post: 12-16-2009, 01:14 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