Page 3 of 3 FirstFirst 123
Results 31 to 37 of 37
  1. #31
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,561
    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

  2. #32
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,234
    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"



  3. #33
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    10,873
    I thought that the Variable Item is the BookingID
    why do you think that when you said itm was highlighted?

    as far as lngitem is concerned, you are not using it, so doesn't need to be declared. But itm does

  4. #34
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,234
    Hi CJ
    How am I supposed to Declare itm?

    Tried this
    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
    But now gives the following Error and highlights "itm" in the line "For Each Itm In List9.ItemsSelected":-
    Attached Thumbnails Attached Thumbnails Error.png  

  5. #35
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    10,873
    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

  6. #36
    GPGeorge is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    1
    Is lngItm intended to be the same thing as Itm? Did you choose a different name for a reason?

  7. #37
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,082
    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.

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 08-21-2020, 03:49 PM
  2. Replies: 19
    Last Post: 10-03-2017, 09:10 AM
  3. Replies: 3
    Last Post: 01-26-2015, 04:25 AM
  4. Append Query Saving Multiple Records
    By jewll in forum Queries
    Replies: 5
    Last Post: 12-13-2014, 03:54 AM
  5. Replies: 5
    Last Post: 12-12-2011, 08:08 AM

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