vba - Trying to open a form using DoCmd.OpenForm based on sub form control -


i have unbound form unbound control (text0). in text0 enter refno. want open form (frmdisclosure) has subform (frmrefnoslist) containing refno. code opening frmdisclosure is: private sub command8_click()

dim refce variant  docmd.openform "frmdisclosure" forms!frmdisclosure.filteron = false refce = "forms!frmdisclosure!frmrefnoslist.form!refno" docmd.openform "frmdisclosure", acnormal, "", refce & " = " & me.text0, , acnormal  end sub 

after our discussion in chat, mocked-up looks trying do:

link access file mock-up.

to others might read later here few clarifications:

  • form form1 has textbox called text0 on , button.
  • when button pressed supposed open form2 has subform on it.
  • form2 supposed open record , filter records shown on subform using value provided in text0

here's mock-up of form1 looks like:

enter image description here

so when provide refno , click button...

enter image description here

... following code (annotated) run on click event of button:

private sub cmdopen_click()      ' check user has provided refno in textbox...     if _         me.text0 = "" or _         isnull(me.text0) _              ' ...if refno has not been provided, give error message         msgbox "please provide ref no.", vbexclamation or vbokonly, "disclosure search"      else          ' ...if refno has been provided, in table lists applicant's         ' forms , return applicantid (or equivalent field you're using) refno provided         dim varapplicantid variant         varapplicantid = dlookup("applicantid", "tblrefnos", "refno=" & me.text0)          ' ...check applicant record can found refno provided         if _             isnull(varapplicantid) _                      '... if applicant record not found, give error message             msgbox "could not find applicant refno provided.", vbexclamation or vbokonly, "disclosure search"          else              '... if applicant record found, open form2 applicant's record             docmd.openform "form2", , , "applicantid=" & varapplicantid              '... , filter subform on form2 refno provided             forms!form2!frmapplicantforms_sub.form.filter = "refno=" & me.text0             forms!form2!frmapplicantforms_sub.form.filteron = true             forms!form2!frmapplicantforms_sub.form.requery          end if      end if  end sub 

this should result in form2 opening correct applicant record derived refno provided , filter subform refno provided:

enter image description here

your exact project layout may differ i've mocked-up, of may need tweaked set up, principles i've illustrated here easy enough translate.

good luck!


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -