• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

Value not getting passed to Popup Form

I am trying to pass a value from one form to the next when selecting an option on a combobox.  The subform opens just fine, but when I try to save it, it tells me the key value is null.  The key value is the value I thought I passed in the arguments.  It is an automated number field in the main form and a number field in the subform.  What am I missing?

Private Sub Combo345_Change()
If Combo345.Value = "Specific Dates" Then
  DoCmd.RunCommand acCmdSaveRecord
  DoCmd.OpenForm "frmSpecificDates", , , "ContractDBNumber =" & Me.ContractDBNumber.Value
Else
  If Combo345.Value = "per Airing" Then
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.OpenForm "frmPerAiring", , , "ContractDBNumber =" & Me.ContractDBNumber.Value
  End If
End If
End Sub
0
haident
Asked:
haident
1 Solution
 
Anthony BerenguelCommented:
What is the value you are trying to pass? Me.ContractDBNumber.value?
0
 
PatHartmanCommented:
Let's start by getting our terminology straight.  A subform is a form that is embedded in a control on another form.  In addition to all the attributes it has as a form, the control it sits in has additional attributes that are used for passing information from the main form to the sub form.  A pop up form is a stand alone form and has no relationship to any other form.  It is called a pop up because it is opened by a different form which is left visible in the background and is usually modal so focus remains on it until you finish with it and close it.

You have a popup form and so there is no link with the form that opened it.  You are using arguments of the OpenForm method to pass in a where clause to control what record the form opens to.  But since this isn't a subform, there are no master/child links defined.  That means that if the popup is related to the main form and it needs to include a foreign key in its Record when it is saved, YOU have to handle that.

If the form is opened from multiple other forms, the best option is to pass in the FK using the OpenArgs argument.  Then in the popup form's BeforeInsert event, you would populate the FK with the value from the OpenArgs.

Me.FK = Me.OpenArgs

Open in new window


Make sure you use the Form's BeforeInsert event because you do not want to dirty the form before the user does.

PS - ALWAYS give your controls meaningful names BEFORE you add code events.  Now, when you rename the control, you will disconnect from any event code so you'll have to open the code module, find the event code, and change its name.

PPS - When referencing form fields the .Value property is optional since it is the default property.   And using Me. gives you the advantage of intellisense (Access recognizes what you are typing and offers help) and is also more efficient since Access knows immediately what class module it needs to access to fine the definition of a variable.
0
 
hnasrCommented:
Where is the code opening the subform? Is it in the main form? Do we have 2 subforms?

Upload a sample database depicting the problem.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
haidentAuthor Commented:
Thanks for the info.  First time doing popups.

So in the BeforeInsert data event I added

Me.ContractDBNumber = Me.OpenArgs

Still get same error.  ?
0
 
PatHartmanCommented:
Did you check the arguments of the OpenForm?  The OpenArgs is the LAST argument.  You were filling in the Where argument.
0
 
haidentAuthor Commented:
Thanks.  I corrected that.  Now I get the errror message 2113
"The value entered isn't valid for this field."
with the system highlighiting the row below (one with>>>>>)

Private Sub Form_BeforeUpdate(Cancel As Integer)
>>>>>>>>>>>>>>Me.[ContractDBNumberSpecificDates] = Me.OpenArgs
End Sub

How can I see what I'm passing to make sure?
It should just be a number.  
THe file is data type number in the new table, and it is a auto number field in the original table.
0
 
PatHartmanCommented:
Add a stop to the code.  Then print the value in the debug window.  

? Me.OpenArgs


Or use
Debug.Print Me.OpenArgs in the procedure to print automatically.
0
 
haidentAuthor Commented:
I ended up just making a subtable and tabbed forms to address this issue.
Nothins recommended helped me.
Thanks!
0
 
BitsqueezerCommented:
Hi,

if you supplied what you had before as Where argument now in the OpenArgs then you have a string like that in OpenArgs:

"ContractDBNumber = 1234"

Of course you cannot fill that value into a field which is bound to a number field. So the argument in DoCmd.OpenForm must be simply that:

DoCmd.OpenForm FormName:="frmPerAiring", OpenArgs:= Nz(Me.ContractDBNumber,0)

Open in new window


The shown syntax is useful in case of functions with a lot of optional arguments like OpenForm where you only use few of them. On this way you don't need to count the commas and look into the tooltip to see if you are at the right parameter, moreover it is easier to read.
The Nz makes sure that a NULL will be converted into a 0 so OpenArgs always have a value in the opened form. Of course you can do the same without the Nz here and test the OpenArgs in the opened form instead if it is NULL (which would for example be the case if you open the form directly and not with your code).

A hint for future questions: If you create a quick example database file containing the needed tables with some demo data and the needed forms and code and upload that here like recommended by hnasr above you would get quicker answers. You should also answer questions and always describe the error exactly and nothing like "did not work" or "got an error" or something similar not very useful for anyone who tries to help you.

It is also strange that you wrote that this returns an error:
Me.[ContractDBNumberSpecificDates] = Me.OpenArgs

where you want to use a field Me.ContractDBNumber to be filled with the value above...

Cheers,

Christian
0
 
haidentAuthor Commented:
Nothing suggested helped me fix my problem.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now