Lookup function in VB6 -
i have table in excel file called " employee_states_file".this table contains 2 columns name , states. both columns filled data. province table contains abbreviation of states such " ne, wa" , so. have excel file called " states_file" contains table has 2 columns: abbreviation , fullstatename. table considered lookup table full state names based on abbreviation. now, want write code in vb6 when user click button, abbreviation names in table of excel file " employee_states" changes full state names based on lookup table of excel sheet " states_file". make sense? please help,
if allowed convert them csv files (comma delimited text files) can use jet database engine , normal sql joins.
i use setup connection.
public function opentextconnection(byval filename string) connection dim fso filesystemobject dim dbfolder string dim ts textstream set fso = new filesystemobject dbfolder = fso.getparentfoldername(filename) if fso.fileexists(fso.buildpath(dbfolder, "schema.ini")) fso.deletefile (fso.buildpath(dbfolder, "schema.ini")) end if set ts = fso.createtextfile(fso.buildpath(dbfolder, "schema.ini")) ts.writeline "[" & fso.getfilename(filename) & "]" ts.writeline "format=csvdelimited" ts.writeline "colnameheader = true" ts.writeline "maxscanrows = 0" ts.close set opentextconnection = new connection if fso.folderexists(dbfolder) opentextconnection.open "provider=microsoft.jet.oledb.4.0;data source=" & dbfolder & ";extended properties=""text;hdr=yes;fmt=delimited;"";" else msgbox dbfolder & " not exists.", vbexclamation end if end function
each file table in connection , can sql joins. note example open table. can use valid sql syntax.
dim db1 connection dim tb recordset dim fso filesystemobject dim timport new dbimportlist set fso = new filesystemobject set timport = new dbimportlist if fso.fileexists(filename) set db1 = opentextconnection(filename) set tb = new recordset tb.open "select * [" & fso.getfile(filename).name & "]", db1, adopenkeyset, adlockoptimistic, adcmdtext end if
Comments
Post a Comment