Select SQL Statement in Excel VBA -
sub logcheck() dim cn object dim rs object dim strsql string dim strconnection string dim apppath string set cn = createobject("adodb.connection") apppath = application.activeworkbook.path strconnection = "provider=microsoft.ace.oledb.12.0;" & _ "data source=c:\ceo.accdb;" cn.open strconnection s_id = sheets("my").range("a1").value strsql = "select * edo id = ' " & s_id & " '" rs.open strsql, cn if rs = null msgbox "record not found" else msgbox "record found" end if end sub
i unable run code. showing error. please me out. thanks! here s_id
data search table & id primary key in edo table.
in case may detect if recordset empty checking .eof
property:
sub testifrecordfound() dim strconnection string dim strid string dim strquery string dim objconnection object dim objrecordset object strconnection = _ "provider=microsoft.ace.oledb.12.0;" & _ "data source='c:\ceo.accdb';" strid = sheets("my").range("a1").value strquery = _ "select * edo id = '" & strid & "';" set objconnection = createobject("adodb.connection") objconnection.open strconnection set objrecordset = objconnection.execute(strquery) if objrecordset.eof msgbox "record not found" else msgbox "record found" end if objconnection.close end sub
Comments
Post a Comment