Hi,

I am using VB 2008 Express to connect to an Access 2007 database.

I have a combo box named cboYEARMONTH that is populated by the database. I have this part working great.

When the user selects a YEARMONTH with the combo box I want the SelectedIndexChanged event to initiate a query in my database called ExactReprints_Query and limit the results to the YEARMONTH selected in the combo box. The results will then be output to a text box called TxtExactReprints.

Can anyone please help me figure out how to code this part?

Thanks in advance,
Diana

Member Avatar for Unhnd_Exception

sub cmbYearMonth_SelectedIndexChanged(byval sender as object, byval e as eventargs) handles cmbyearmonth.selectedindexchanged

dim conn as new sqlconnection("?")
dim com as new sqlcommand
dim reader as sqldatareader

com.connection = conn
com.comandtype = storedprocedure
com.commandtext = "ExactReprints_Query"

com.parameters.addwithvalue("@YearMonth", cmbYearMonth.selecteditem) 'or what ever else your parameter is

txtExactReprints.clear

try
con.open

reader = com.executereader
do while reader.read
txtExactReprints.text &= reader.item("?") & vbtab
end while

catch

finally
conn.dispose
com.dispose
if reader isnot nothing then reader.dispose
end try

end sub

write some of your codes out so we can figure out where the problem is

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.