database - Passing selected items from list box to a control source -


i'm trying pass selected items list box mover , assign control source "vocabularyfocus" junction table.

the "vocabularyfocus" junction table has 2 primary key fields "vocabidfk" , "unitidfk". intent assign selected items specific unit within course book.

i have following code list box, need vba procedure cmdassign_click() in order pass selected items unit specified in "txtunt" unbound box.

i have following code below:

option compare database option explicit  private sub cmdadd_click()  dim in_clause string: in_clause = "" dim strsql string, n integer  ' iterate build comma-separated list sql in() clause me.lfmvocabulary     n = 0 .listcount - 1        if .selected(n) = true            in_clause = in_clause & .itemdata(n) & ", "        end if     next n end  ' remove last comma , space in_clause = left(in_clause, len(in_clause) - 2)  strsql = "select * vocabulary" _            & " vocabid in (" & in_clause & ")"  me.lfmvocabularyassign.rowsource = strsql me.lfmvocabularyassign.rowsourcetype = "table/query" me.lfmvocabularyassign.requery  end sub  private sub cmdassign_click()    end sub  private sub cmdclearall1_click()   dim n integer      me.lfmvocabulary         n = 0 .listcount - 1             .selected(n) = false         next n     end  end sub  private sub cmdclearall2_click()   dim n integer      me.lfmvocabularyassign         n = 0 .listcount - 1             .selected(n) = false         next n     end  end sub  private sub cmdremove_click()  dim in_clause string: in_clause = "" dim strsql string, n integer 'set sql current sql strsql = me.lfmvocabularyassign.rowsource   ' iterate remove items comma-separated list sql in() clause me.lfmvocabularyassign     n = 0 .listcount - 1        if .selected(n) = true            if instr(1, strsql, ", " & .itemdata(n)) <> 0                 'not first item, nor item                 strsql = replace(strsql, ", " & .itemdata(n), "")            elseif instr(1, strsql, .itemdata(n) & ", ") <> 0                 'it's first item                 strsql = replace(strsql, .itemdata(n) & ", ", "")             else                 'it's item                 strsql = replace(strsql, .itemdata(n), "")             end if        end if     next n end   me.lfmvocabularyassign.rowsource = strsql me.lfmvocabularyassign.rowsourcetype = "table/query" me.lfmvocabularyassign.requery  end sub private sub cmdselectall1_click()   dim n integer      me.lfmvocabulary         n = 0 .listcount - 1             .selected(n) = true         next n     end  end sub   private sub cmdselectall2_click()  dim n integer      me.lfmvocabularyassign         n = 0 .listcount - 1             .selected(n) = true         next n     end end sub   private sub form_load()      me.lfmvocabularyassign.rowsource = ""     me.lfmvocabulary.rowsource = "vocabulary"     me.lfmvocabulary.rowsourcetype = "table/query"     me.lfmvocabulary.requery  end sub  private sub txtsearchbox_change()      dim strwhere string         me.txtsearchbox           if .text = vbnullstring           strwhere = "(false)"         else           strwhere = "vocabulary """ & .text & "*"""         end if         end          me.lfmvocabulary         .filter = strwhere         .filteron = true         end  end sub 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -