Question : Pass value from one form to another

Hi,

I have an unbound form... called "frmAction".   This form contains a combo box listing existing records (one field = companyname) from tblCompanies.  

When I scroll down and select "companyname" from the combo, another form (bound to tblCompanies) opens and shows the proper record... so far so good.

If I want to add a new company to tblCompanies, I simply enter its name, press ENTER... then the bound form opens with all fields blank (as expected since the record doesn't exist yet).

Here's what I want to do... since I already typed the value for a new company into the combo of frmAction, I want to at least pass that companyname value into the bound form.

I thought the following might work... but it doesn't:

1. create module and add "Public strCombo1 As String"
2. in frmAction (before the AfterUpdate executes the OpenForm, add "strCombo1 = Me.cboAction.Value"
3. in frmCompany, add "Me.CompanyName = strCombo1" to the OnLoad function

Steps 1 to 3 have always worked fine for me when passing values from one form to another.   But I guess, this is different now since frmCompanyName is bound to a table.

Quick recap:  
a. If company exist in combo box of frmAction, I select value and frmCompany opens with all fields populated
b. If company does not exist, I type in value into combo box, then frmCompany opens with just company name populated... while all other fields are empty (since it's a new record)

Any ideas how to differentiate between "existing record... do not pass value" ... or "new record... do pass company name value"?

Thanks,
Tom

Answer : Pass value from one form to another

Alter the calling code to more like this

        If Not IsNull(Me.cboAction) Then
            DoCmd.OpenForm FormName:="frmCompanies", _
                        WhereCondition:="[CompanyName]=" & "'" & Me![cboAction] & "'", OpenArgs:=Me.cboAction
        End If


And then In frmCompanies try using the current event:
============
Private Sub Form_Current()

    DoCmd.Restore
   
    If Me.NewRecord Then
       Me.CompanyName.DefaultValue = Me.OpenArgs
    End If
   
End Sub
Random Solutions  
 
programming4us programming4us