Results 1 to 5 of 5
  1. #1
    habinalshaikh is offline Novice
    Windows 10 Access 2019
    Join Date
    Jul 2024
    Posts
    1

    How to insert multi valued field in a table using access vba

    I'm writing a program by using MS Access VBA.


    In this program I have textboxes that I fill them out and once I click on the button it inserts the values which are in the textboxes to a table named "Programs", but I have a lookup field that allows to select multi-values and I can't add the values into the Program table.

    I have tried the following code:



    Private Sub btnAdd_Click()

    CurrentDb.Execute _
    "INSERT INTO Programs " & _
    "(Program_Name, Objectives, Targetted_Competency.[Value]) " & _
    "VALUES ('" & Me.txtProgramName & " ', '" & Me.txtObjectives & " ', '" & Me.Targetted_Competency & " ')"

    Programs_subform.Form.Requery


    End Sub




    but it displays error " Type mismatch", although all textboxes have been added into "Programs" table except the multivalued field which named "Targetted_Competency"

    can any one help me with this?
    Attached Thumbnails Attached Thumbnails Capture2024.PNG   Capture VBA code.PNG  

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    First, multi value table fields are to be avoided. It is something you can create, but that doesn't mean you should. This design saves casual users from having to learn proper table design and relationships. The table that provides the mvf list is a hidden table that you cannot see, and I only know one person who might even know where it is (and he would never use them either). So forget about populating it with your list items. Instead, learn proper db normalization and ditch the mvf in your table. You will only have issues with it down the road.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    I agree that MVF should be avoided, but please let us know what happens if you try it like this:
    Code:
    CurrentDb.Execute _
    "INSERT INTO Programs " & _
    "(Program_Name, Objectives, Targetted_Competency.[Value]) " & _
    "VALUES ('" & Me.txtProgramName & " ', '" & Me.txtObjectives & " ', '" & Me.Targetted_Competency.Value & " ')"
    
    
    Programs_subform.Form.Requery
    Here is a link to Colin's article about MVF:
    https://www.isladogs.co.uk/multivalued-fields/

    https://support.microsoft.com/en-us/...3-b6624e1e323a
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Nice spot. Now on my IL.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-18-2019, 12:00 AM
  2. Replies: 4
    Last Post: 06-12-2018, 06:22 AM
  3. Replies: 2
    Last Post: 02-19-2013, 04:02 PM
  4. Multi Valued field sort
    By bugman61 in forum Reports
    Replies: 2
    Last Post: 08-06-2011, 11:45 AM
  5. Append Query - Multi-Valued Field
    By catat in forum Queries
    Replies: 0
    Last Post: 05-11-2010, 01:52 PM

Tags for this Thread

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