database - ACCESS 2010 - Autopopulating text fields based off of two comboboxes -


i have 2 tables right now. 1 called workstations[id, workstationname, image, operating system] , other machines[id,asset tag, serial number, mac, comments]. have 2 comboboxes right now. 1 workstation table shows list of workstationname's(cboworkstationname) , other machines table shows list of assettags (cboassettags)

the goal in making form when select value in cboworkstationname, autopopulate text fields based off of workstations table, combobox cboassettags autopopulate fields related machines table based off of second combobox. in end, want able save different asset tag data workstation using drop down lists.

right now, cboworkstationname autopopulates text fields based off of workstations table , cboassettags, not populate textfields based off of machines table. however, when click asset tag (from second combobox) autopopulates related fields. it's not filling every field.

in regards how i'm autopopulating, first combobox, bound form first table, , set inherit value list yes. second combobox, set control source id. text fields below second combobox, wrote following code onchange event.

me.txtserialnumber.value = me.cboassettag.column(2) me.txtmac.value = me.cboassettag.column(3) me.txtcomments2.value = me.cboassettag.column(4) 

i'm thinking have add line of code somewhere refreshes/runs second combobox when change first one.

if need clarifications please let me know.

thanks in advance!

edit:

private sub cboworkstationid_change() dim db database dim rec1 recordset dim rec2 recordset  set db = currentdb set rec1 = db.openrecordset("select * workstations id = " &     me.cboworkstationid.column(0) & "") set rec2 = db.openrecordset("select * machines id = " & me.cboassettag.column(0) & "")  me.txtcomments.value = rec1("comments") me.txtimage.value = rec1("image") me.txtoperatingsystem.value = rec1("operating system") me.txtlocation.value = rec1("location") me.txtserialnumber.value = rec2("serial number") me.txtmac.value = rec2("mac") me.txtcomments2.value = rec2("comments")   set rec1 = nothing set rec2 = nothing set db = nothing end sub 

it better if used query fill textboxes. write function, , execute function in onchange event of both combo's. like:

dim db database dim rec1 recordset dim rec2 recordset  set db = currentdb set rec1 = db.openrecordset("select * workstations id = " & me.cboworkstationname.column(0) & "") set rec2 = db.openrecordset("select * machines id = " & me.cboassettags.column(0) & "")  me.txtworkstationname.value = rec1("workstationname") me.txtserialnumber.value = rec2("serial number") me.txtmac.value = rec2("mac") etc...  set rec1 = nothing set rec2 = nothing set db = nothing 

you can fill in rest of fields accordingly. make sure combo's have default value, or have type of error trapping/coded default value run first time change combo.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -