Code not working for Access 2007 Open Form Wizard

Travwoody
Travwoody used Ask the Experts™
on
Good evening!

Though the code is probably very close, I was not able to get this working in an application I am building using two unbound forms.  When I click the button now nothing happens.  I have one form (frmSurveyResults) that will open to another (frmSurveyResultsPg2) to complete a record in a table.  Initially I need this to open to a new form.  However, in this case I need the form to open to an existing table field called "SurveyID".  The following is what I have from your example:
Private Sub Command402_Click()
DoCmd.OpenForm "frmSurveyResultsPg2", , , "SurveyID=" & Me.SurveyID
End Sub[
Your help is greatly appreciated!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
< I am building using two unbound forms.>

the codes you are using will never work in UNBOUND forms..

the form must be BOUND.

if the name of table is tblSurvey, use it as the Record Source of form  "frmSurveyResultsPg2"

then this codes will work



if SurveyID is Number Data Type, use this

DoCmd.OpenForm "frmSurveyResultsPg2", , , "SurveyID=" & Me.SurveyID

if SurveyID is Text Data Type, use this

DoCmd.OpenForm "frmSurveyResultsPg2", , , "SurveyID='" & Me.SurveyID & "'"





Top Expert 2016

Commented:
also, your Database must be in a Trusted Location to enable the Codes to work
Top Expert 2006
Commented:
if frmSurveryResultsPg2 is bounded to a table then your line would work. But because you said it is unbounded you have to do the work yourself.

How do you currently load data into frmSurveryResultsPg2? Or is this not done yet?

you could make the form bounded then make it read only (by disallowing edits, adds and deletes) or call it readonly

DoCmd.OpenForm "frmSurveyResultsPg2", , , "SurveyID=" & Me.SurveyID,acFormReadOnly

Be the easiest

Otherwise last argument is argument passing between forms
eg
DoCmd.OpenForm "frmSurveyResultsPg2", , , , , , Me.SurveyID

then in form_open or form_load of frmSurveryResultsPg2 you can get the survey id by referencing prefefined variable OpenArgs
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Author

Commented:
I was able to go around the restrictions that I was facing by using the tabbed form in Access 2007.  This gave me more room to list out form fields so that I did not have to use a second form.  However I also could not get the list to populate even when using a bound form and then going through the wizard.  Though the forms had related fields from the same table, the fields never showed up in using the wizard.

Author

Commented:
This question is answered and seems to be a limitation or program issue.
Top Expert 2006

Commented:
How has the question been answered? Please advise as two similar answers given with a similar time.

Did you try argument passing? from what I gather you do not have seem to have bothered to try it. If you are using two unbounded forms as you clearly said, you can pass the survery id in using argument passing. Obviously since you have unbounded forms you have code already that reads the table and populates your form.

Going by the rules of a previous post I was dealing with you have to post your own solution or if nothing worked then request a delete with refund or accept your own comments.
Top Expert 2006

Commented:
Let me know if you tried argument passing
i.e. what I mentioned in my first post


Otherwise last argument is argument passing between forms
eg
DoCmd.OpenForm "frmSurveyResultsPg2", , , , , , Me.SurveyID

then in form_open or form_load of frmSurveryResultsPg2 you can get the survey id by referencing prefefined variable OpenArgs


If you need more information then ask

Author

Commented:
I guess that the question itself was only patially answered.  I did use the VBA code and it partially worked.  However I could never get the two forms to cooperate very well on one table so I actuallu redesigned this so that I used a tabbed form, thus elliminating the need for two separate forms to feed into one table.  This was a much easier solution for me and for those that will be entering data later.  I got this solution by further researching forms on a spearate site.

Author

Commented:
This is only a partial solution.  The form length was my problem as I had a lot of fields in the form  and therefore had to break it into two separate forms.  Tabbed view took care of this.
Top Expert 2006

Commented:
to use two forms based one table is possible considering you are using unbounded forms as there is no locking problems unless lock introduced in one form and a update in the other. Like I said before using OpenArgs will allow you to pass the survery id between two forms without problems.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial