Suggest you add
Option Explicit
at the top of your module as a standard practice.
Then, Access will point to your error.
As CJ said you have not declared itm
Suggest you add
Option Explicit
at the top of your module as a standard practice.
Then, Access will point to your error.
As CJ said you have not declared itm
Hi CJ
This is where my lack of VB knowledge lets me down
I thought that the Variable Item is the BookingID
Do I need to Dim lngItm at all ? as in the Code it is saying "rs!BookingID = itm"
why do you think that when you said itm was highlighted?I thought that the Variable Item is the BookingID
as far as lngitem is concerned, you are not using it, so doesn't need to be declared. But itm does
Hi CJ
How am I supposed to Declare itm?
Tried this
But now gives the following Error and highlights "itm" in the line "For Each Itm In List9.ItemsSelected":-Code:Private Sub cmdInsert_Click() Dim db As Database Dim RS As Recordset Dim Itm As Long Itm = Me.BookingID Set db = CurrentDb() Set RS = db.OpenRecordset("tblBilling") For Each Itm In List9.ItemsSelected RS.AddNew RS!BillNo = BillNo.ItemData(Itm) RS!BookingID = Itm RS.Update Next RS.Close Set RS = Nothing Set db = Nothing End Sub
what does the error message tell you?
edit - a simple google will tell you all about listbox properties
https://learn.microsoft.com/en-us/of....itemsselected
Is lngItm intended to be the same thing as Itm? Did you choose a different name for a reason?
Dim Itm As Variant.
RS!BillNo = Itm
RS!BookingID = Me.BookingID
That assumes listbox has BillNo in first column even if it is hidden. If it is not in first column, reference column by index. Index begins with 0 so if data is in second column, index is 1:
RS!BillNo = List9.Column(1, Itm)
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.