Friday, 15 May 2015

vba find variable match in table to prevent duplicates -



vba find variable match in table to prevent duplicates -

i have been searching reply how on month little help.

what trying do: have access 2013 database (accdb) need import excel (csv) reports into. got import vba working correctly. reports weekly site , utilize info improve access. trying create sure import doesnt allow same study imported, prevent duplicates. trying query results several reports , imports go 1 table. have added field table import date/time default now() can see study record belongs to. need seek , update table csv study filename date(20140625.csv). think got part working correctly too, record value 20140625.

the problem im having: cant search filename record in table , not allow import if record matches filename. have tried dlookup , several different things. nil working.

here have far:

sub importcsv() 'first add together reference microsoft office object library dim strfilename string dim rptn string dim rptf string dim string application.filedialog(msofiledialogfilepicker) .title = "select csv file import" .allowmultiselect = false .filters.clear .filters.add "csv files", "*.csv", 1 .filters.add "all files", "*.*", 2 if .show = -1 strfilename = .selecteditems(1) rptf = right(strfilename, len(strfilename) - instrrev(strfilename, "\")) rptn = left(rptf, instrrev(rptf, ".") - 1) end if end 'dlookup not finding first record in table = dlookup("[rptname]", "tblcsvlog", "[rptname] = 'rptn'") if rptn = 'if rptn = docmd.findrecord("'rptn'") = true msgbox "report " & rptf & " exists" goto hell 'end if else 'import works docmd.transfertext acimportdelim, , "globalrptcsv", strfilename, true 'add filename table works docmd.runsql ("insert tblcsvlog ([rptname])values (" & rptn & ")") hell: 'else 'exit sub end if 'end exit sub end sub

any ideas? tried kinds of variations of dlookup variable rptn, "rptn", "'rptn'". nil finding match in table. in advance.

you seem have confused variable name. try:

look = dlookup("[rptname]", "tblcsvlog", "[rptname] = '" & rptn & "'")

vba variables table

No comments:

Post a Comment