Why wont this code work?

  • Thread starter Thread starter tom
  • Start date Start date
T

tom

The following code asks for a parameter invoice number
and after plugging in the proper invoice number
the form will open as I want it to work.

I have tried all kinds of different permutations of this
code and nothing seems to work as I want.

Private Sub ListBoxName_DblClick(Cancel As Integer)
Dim sqlst As String
Dim sqlstmnt As String

sqlst = Me.ListBoxName.Column(0, 0)
sqlstmnt = "[IDNumber] = me.ListBoxName.[invoice number]"

DoCmd.OpenForm "FormName", , , sqlstmnt, , , ""
End Sub
 
Tom,

As far as I know, you can't refer to the name of a column in a listbox.
There are other syntax errors in your code as well. To simplify it,
try this...

Private Sub ListBoxName_DblClick(Cancel As Integer)
DoCmd.OpenForm "FormName", , , "[IDNumber]=" & Me.ListBoxName
End Sub

This assumes the ID is the bound column of the listbox, which does
appear to be the case.

Having said that, as an aside, I would personally prefer the After
Update even tof the listbox, rather than DblClick, which would seem
awkward to me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top