hey
Really strugling with Access today so i could do with some help :)

I'm attempting to add items to a list box. The Sources are 2 text boxes which have been fed to from a querey. So first I tried...

lstReorder.AddItem (ITEM_NUMBER.Text)
lstReorder.AddItem (ITEM_DESCRIPTION_1.Text)

Which brought up the error message
Run Time error '2185' - You cant referance a property or method for a control unless the control has the focus.

So i made sure that the querey was set up right by deselecting the backwards E, and i still get the same error.

I then changed the code to

lstReorder.AddItem (ITEM_NUMBER.Value)
lstReorder.AddItem (ITEM_DESCRIPTION_1.Value)

and i get the error message '6014' - The RowSourceType must be set to 'value list' to use this method

Ive tried every way i know how... and still no luck
Any help would be appreciated
Thanks, Michael

Recommended Answers

All 9 Replies

With lstReorder
    .AddItem (ITEM_NUMBER.Text)
    .AddItem (ITEM_DESCRIPTION_1.Text)
End With
commented: nice +1
commented: thanks +1

I think it's because of the parenthesis, Im' not sure I have no VB here but try to ommit that parenthesis.

With lstReorder    
               .AddItem  ITEM_NUMBER.Text    
               .AddItem ITEM_DESCRIPTION_1.Text
         End With

HI,
No problem with the paranthesis,

no issues if u palcwe or not placing the paranthesis next to the additem property.

With regards
Venkatramasamy SN

what are you trying to get here? why do you want to add an item from a textbox?

Well i actually have 4 text boxes that will be fed to the list box. Its for a Stock Reorder System. The user analyses some of the data, and then decides how many they want to order of that particular item, and then if they wish to change the previous selling price. So i will be adding many records to the list box and then printing the contents of the list box as a reorder list.

The With Statement still does not work :(

With lstReorder
.AddItem ITEM_NUMBER.Text
.AddItem ITEM_DESCRIPTION_1.Text
End With

Gives me The same error message

Run Time error '2185' - You cant referance a property or method for a control unless the control has the focus.

How do i make the Text box the focus??

Any ideas from anyone?
Thanks :)

post the code, it will help much

OK ive sussed it :D but thanks for the help anyway guys!

share the answer please, so if someone get a same problem he can solved it.
thanks friend :)

Well i'm still not sure what i did! but here's the working code.

Option Explicit

Dim ItemNumber As String
Dim ItemDescription As String
Dim Qtytoorder As String
Dim AmmendPrice As Currency

Private Sub cmdAdd_Click()

ItemNumber = ITEM_NUMBER.Value
ItemDescription = ITEM_DESCRIPTION_1.Value

AmmendPrice = txtAmmendPrice.Value
Qtytoorder = txtqtytoorder.Value

With lstReorder
.AddItem AmmendPrice
.AddItem Qtytoorder
.AddItem ItemNumber
.AddItem ItemDescription
End With

End Sub

I have no idea what made this different from the other suggested code... but it WORKS :)

Its still not finished... i need to change it so that the Text boxes are all added to the List box as one record... so i'm looking into that now!! something to do with arrays if i remember back to my college years...

Thanks for the help guys and gals

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.