Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing a field back to a form when using not in list 1

Status
Not open for further replies.

christine4

Programmer
Oct 2, 2000
3
US
I have a form with a combo box that when not in list goes out to another form to add it then comes back to the first form. When it comes back I need to also pass back a department field to the first form. Can't seem to get this to work. If I am not entering a new item I can bring in the department but if entering a new item I can't get it to work.

Any ideas?
[sig][/sig]
 
Why don't you create a public variable to assign the department to while you are on the second form? When you come back, you just refer to that variable. [sig]<p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development[/sig]
 
Check to see that the department is included in the data source so that when you requery the control it requeries the department as well.

Umbane
[sig][/sig]
 
Christine
I use the following code to do this. It is run from the CloseForm event of the second form.


Code:
Private Sub cmdCloseForm_Click()
On Error GoTo Err_cmdCloseForm_Click

'If main form is open, close current form and
'return focus to the main form.
    DoCmd.Hourglass True
    If IsLoaded(&quot;MainForm&quot;) Then
        Dim X As Variant
        X = Me![AccountNumber]
        DoCmd.Close acForm, &quot;CurrentForm&quot;, acSaveYes
        Forms!MainForm![AccountNumber].Requery
        DoEvents
        Forms!MainForm![AccountNumber] = X
        DoCmd.Hourglass False
    Else
    'Otherwise, close this form
        DoCmd.Close
        DoCmd.Hourglass False
    End If

The IsLoaded function is not a built-in Access function, but is included in the Northwind sample database that comes with Access. You can copy it from there into a module in your app.

Hope this helps :)
Lightning
[sig][/sig]
 
Thanks for your help.

Lightning 4 that worked great. [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top