adding new records in popup form

ggreg

Registered User.
Local time
Today, 06:33
Joined
Aug 12, 2002
Messages
66
Here's another question on popup forms.

In my main form I have a subform that has two fields
date and notes.....It is link to the main form by two fields
Des and Type On the form I have a button that makes
this sub form to popup.....When I add data inside the
popup form it adds the data but does not add the des and
type as it does down in the sub form so my data does not show
with the des and type.

I decided I could add the fields des and type to the popup form and put in their default values .....getting the main form des and type then I could hide the fields but in the popup form it does not
put in the default values it only does it in the subform part,

How can I get the popup form to automatically put in des and
Type when I start a new record in date and notes
 
Default values should work on the popup form if it is a new record.

Your problem can happen if:

1) You create a new record in the subform and then open it in the popup. THe record in the popup is not a new record and the default values are not activated. However the field values should be set in the subform, so this is not likely.

2) You are not actually loading the default values from the main form. Try code something like:

Me![Date].DefaultValue = "#" & Forms![MainForm]![Date] & "#"
Me![Type].DefaultValue = "'" & Forms![MainForm]![Type] & "'"

Let me know if this works of what problems you have.
 
Jay,

Thanks a bunch that did exactly what I was wanting it to do!

I did change your lines to below and it works great!

Me![DES].DefaultValue = "'" & Forms![frmjobs]![DES] & "'"
Me![TYPE].DefaultValue = "'" & Forms![frmjobs]![TYPE] & "'"
 
Glad that worked. When we use this code, we test that the Form from which you set the default is open. Under normal circumstances it should be open, but during testing or under some wierd circumstances the "calling Form" may be closed. To prevent an error message, we always test that the form is open. Here's the function we use.

Public Function FormIsOpen(Passname As String) As Integer
On Error GoTo Err_Proc

Dim I As Integer

For I = 0 To Forms.Count - 1
If Forms(I).FormName = Passname Then
FormIsOpen = True
Exit Function
End If
Next I

FormIsOpen = False
Exit Function

Err_Proc:
FormIsOpen = False
Exit Function

End Function

-----
The on the Form_Current event you can set defaults using the following code.

If FormIsOpen("NameOfForm") Then
Me![Control1].Default = "'" &Forms![NameOfForm]![Field] & "'"
End If

Good Luck
 
Thanks for the function and the heads up on the sometime error!
 

Users who are viewing this thread

Back
Top Bottom