Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Value not getting passed to Popup Form

Posted on 2014-01-13
10
Medium Priority
?
420 Views
Last Modified: 2014-01-25
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
Comment
Question by:haident
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 39777471
What is the value you are trying to pass? Me.ContractDBNumber.value?
0
 
LVL 39

Expert Comment

by:PatHartman
ID: 39777474
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
 
LVL 31

Expert Comment

by:hnasr
ID: 39777580
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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Comment

by:haident
ID: 39777619
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
 
LVL 39

Expert Comment

by:PatHartman
ID: 39777742
Did you check the arguments of the OpenForm?  The OpenArgs is the LAST argument.  You were filling in the Where argument.
0
 

Author Comment

by:haident
ID: 39779778
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
 
LVL 39

Expert Comment

by:PatHartman
ID: 39779833
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
 

Accepted Solution

by:
haident earned 0 total points
ID: 39794264
I ended up just making a subtable and tabbed forms to address this issue.
Nothins recommended helped me.
Thanks!
0
 
LVL 24

Expert Comment

by:Bitsqueezer
ID: 39799189
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
 

Author Closing Comment

by:haident
ID: 39808417
Nothing suggested helped me fix my problem.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question