mysql - SQL Query is updated when user updates Excel -


i have excel document want link sql query. in excel document have list of item numbers. whenever item number gets changed want sql query query list of item numbers , return output. want excel sheet use item number parameter database item numbers ? excel item numbers updated daily.

keep in mind mock example trying do. no knowledge of database or spreadsheet, can't guarantee of work. @ least, require make adjustments before can use it.

with in mind, have commented on various parts of code let know going on there. sections have *** areas may want change. sections ### areas have change work you.

this code assumes have list of item numbers in column of sheet 1, each item number return 1 record, , there no blank cells in list of item numbers.

sub grabiteminfo() dim objado new adodb.connection dim objrecset new adodb.recordset dim objcmd new adodb.command dim strconn string dim strsql string dim rownum long dim errnum long  'open connection database '### change properties connection suit needs strconn = "dsn=dsnname; dbq=database; uid=username; pwd=password" objado.open strconn objcmd.activeconnection = objado objcmd.commandtype = adcmdtext  'errnum row error log start on '***change errnum change row starts on errnum = 1 '***changerownum here change row start on rownum = 1 'start loop until thisworkbook.sheets(1).cells(rownum, 1) = ""     on error resume next     '### change sql whatever need     '*** change cells section if you're not using first column     strsql = "select [field] [table] itemnum = " & thisworkbook.sheets(1).cells(rownum, 1).value     objcmd.commandtext = strsql     set objrecset = objcmd.execute     'pastes results query cell next item number     '***change cells section if want use different column     thisworkbook.sheets(1).cells(rownum, 2).copyfromrecordset objrecset     'clear out recordset before loops starts again     set objrecset = nothing     'put item number, error number, , error description on second sheet of work book     '***change sheet number put on sheet if you're using second     if err > 0         thisworkbook.sheets(2).cells(errnum, 1).value = thisworkbook.sheets(1).cells(rownum, 1).value         thisworkbook.sheets(2).cells(errnum, 2).value = err.number         thisworkbook.sheets(2).cells(errnum, 3).value = err.description         on error goto 0     end if     'raise value row next iteration     rownum = rownum + 1 loop  'clear out connection set objado = nothing set objrecset = nothing set objcmd = nothing  end sub 

for more information on connection strings, recommend http://www.connectionstrings.com it's great resource use figuring out kind of connection string need. connections strings can be...tricky...sometimes, , helps.

if need resources sql, recommend http://www.w3schools.com/sql have introduction there. past that, reference book, find mentor, join forums(or q&a sites one), etc. if sql tag on site, there more information, along recommended resources well.

good luck.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -