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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a Form from another Form and Auto-Populate it.

Status
Not open for further replies.

dots

Technical User
Jul 13, 2001
24
US
Hello all,

I have a display only form. I would like users to be able to click on a command button and open another form (same form basically, but in data-entry mode) to add a new record. I need to pass some of the data from the display-only form to the data-entry form.

I have been able to open the new form, but I can't seem to figure out the right code to populate the fields with the data from the first form. I've saved the data into variables before the code opening the form, but they are not populating the fields.

Any suggestions? Thanks in advance.
 
Hi:

Why use two forms? Put some code in the On Current event that will populate your new record with data from the previous record: e.g.,
Code:
Private Sub Form_Current()
  Dim rs As Object
  Set rs = Me.Recordset.Clone    
  If rs.EOF Or Not Me.NewRecord Then
Code:
    'Don't do anything if there are_
     no records or it is not a new
     record
Code:
  Else
    With rs
       .MoveNext
       Me![City] = .Fields("strCity")
       Me![PostalCode] = .Fields("strPostalCode")
       Me![Region] = .Fields("strRegion")
    End With
  End If    
End Sub

I swiped this code from MS' sample database: frmsmp00.

Hope this is helpful. I'm really pleased with my new diet--I've been on it about a week and I've yet to gain 5 pounds.
Gus Brunston [glasses] An old PICKer, using Access2000.
 
Use unbound text boxes and save them in the command button that opens the new form - then set the values in the opened form with the saved values. me.fields(0), me.fields(1) etc.

rollie@bwsys.net

email for an example.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top