0

ISSUE

I have two forms:

  • frmForms
  • frmDockRental

I have two controls associated with this issue:

  • lstOwners on frmForms (unbound)
  • cboOwner on frmDockRental (unbound)

The second form (frmDockRental) is opened using different listboxes located on frmForms (See Image). I have one such listbox that's giving me grief. It is a filtered list of contacts that when double-clicked it should be opening frmDockRental to a NEW record and set cboOwner, which is unbound, to a specific item in the list. The same item listed in lstOwners from frmForms.

CODE

After a lot of fiddling, I came up with this - except nothing happens at all.

Private Sub lstOwners_DblClick(Cancel As Integer)
On Error GoTo lstOwners_DblClick_Err

    On Error Resume Next
    If (Form.Dirty) Then
        DoCmd.RunCommand acCmdSaveRecord
    End If
    If (MacroError.Number <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
        Exit Sub
    End If
    On Error GoTo 0
    Exit Sub

    DoCmd.OpenForm "frmDockRental", acNormal, "", "", acFormAdd, acDialog, Me.lstOwners
    DoCmd.Close acForm, Me.Name

lstOwners_DblClick_Exit:
    Exit Sub

lstOwners_DblClick_Err:
    MsgBox Error$
    Resume lstOwners_DblClick_Exit
End Sub

And on frmDockRental, this:

Private Sub Form_Load()
On Error GoTo Form_Load_Err

    DoCmd.MoveSize , , 5.3 * 1440, 5.2 * 1440
'    If (IsNull(OpenArgs)) Then
'        Exit Sub
'    End If
    If Me.OpenArgs <> vbNullString Then
        Me.cboOwner = Me.OpenArgs
    End If
    If (Not IsNull(OpenArgs)) Then
        DoCmd.GoToRecord , "", acNewRec
    End If

Form_Load_Exit:
    Exit Sub

Form_Load_Err:
    MsgBox Error$
    Resume Form_Load_Exit
End Sub

I figured OpenArgs would be the best method to accomplish this, but it just doesn't work. Nothing at all happens. No errors, just nothing.

frmForms

EDIT:

Here's an image of the step debugging.

Step Debugging

BeardedSith
  • 129
  • 11
  • 1
    Have you step debugged? Use Me.Dirty instead for Form.Dirty. – June7 Jun 03 '19 at 19:15
  • 1
    You set breakpoint and step debugged? The procedure doesn't even start? Disable the `On Error` lines and see what happens. – June7 Jun 04 '19 at 13:03
  • 1
    Image shows code is running. I just noticed `Exit Sub` just before OpenForm line. Code never gets to open form. Suggest you remove that line. For VBA error handler review http://allenbrowne.com/ser-23a.html – June7 Jun 04 '19 at 19:09
  • Oops! Fixed that. ``frmDockRental`` still doesn't assign ``cboOwner`` a value. When it opens, it opens blank. I have a feeling it's something wrong with one or both of these two lines of code: ``DoCmd.OpenForm "frmDockRental", acNormal, "", "", acFormAdd, acDialog, Me.lstOwners`` which opens the form, and ``If Me.OpenArgs <> vbNullString Then Me.cboOwner = Me.OpenArgs End If `` which is on the form load. - EDIT: Deleted unnecessary comments. – BeardedSith Jun 06 '19 at 13:53
  • 1
    So does OpenArgs have the listbox value? Again, step debug. Does the `Me.cboOwner = Me.OpenArgs` line ever execute? – June7 Jun 06 '19 at 20:27
  • Figured it out - sigh. I had a blurb in there stating ``If (Not IsNull (OpenArgs)`` sending me to a new record. Commented that out and it worked. That's what I get for trying too many things at once. Thanks @June7! – BeardedSith Jun 07 '19 at 12:07

0 Answers0