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

New record based on another record 1

Status
Not open for further replies.

Dophia

Technical User
Jul 26, 2004
263
CA
Hello Everyone:

I am trying to open a form and add a new record with information from the previous form which displayed the data.

I have this, which opens a new form, but it is blank. How can I get it to put the data in the previous form's field into the new form's field?

Private Sub AddByLaw_Click()
On Error GoTo Err_AddByLaw_Click

Dim stDocName As String

stDocName = "FrmBy_Law_Case"
DoCmd.OpenForm stDocName, , , Forms!FrmPhoneCalls_By_Laws!.Phone_Log = " &Me![PhoneID}"


Exit_AddByLaw_Click:
Exit Sub

Err_AddByLaw_Click:
MsgBox Err.Description
Resume Exit_AddByLaw_Click

End Sub
 
Did you copy and paste your code? Do you really have a "}" in the code?
How many controls in the form FrmBy_Law_Case do you want to fill in?
Do you always open the FrmBy_Law_Case from frmPhoneCalls_By_Laws?
Is the code you shared running in the form frmPhoneCalls_By_Laws?

Your quotes in the WHERE CONDITION are wonky. I think you want something like:
Code:
DoCmd.OpenForm stDocName, , , "[PhoneID] = " & Me![PhoneID]
I could be wrong since I don't know the data type or whic form has the code.

Duane
Hook'D on Access
MS Access MVP
 
Hi Duane: Thanks for your help. I copied your questions and will answer them.

Did you copy and paste your code? Do you really have a "}" in the code?.....Yes, by accident :(
How many controls in the form FrmBy_Law_Case do you want to fill in? ......I just want to fill in one field, which is the PhoneID field.
Do you always open the FrmBy_Law_Case from frmPhoneCalls_By_Laws? ........No, I want to be able to open the FrmBy_Law_Case from a menu too.
Is the code you shared running in the form frmPhoneCalls_By_Laws? .....Yes, It is a command button event.

To explain a bit more. The frmPhoneCalls_by_Laws is based on a table of phone calls, with a Phone_Log field that is a primary auto-number field. FrmBy_Law_Case is based on a table that will relate to the other table, with a one to many relationship. Both fields are the same, with a one to many relationship.

I want to be able to view a list of phone calls and click a button to open a Case, based on the phone field. Sort of like an issue tracking situation.

Sophia
 
If you want a value (PhoneID) from formA to be used in a formB which is opened from FormA, use the OpenArgs to set the default value in FormB.

Code in FormA:
Code:
DoCmd.OpenForm "FormA", acNormal, , , , , Me.PhoneID

Code in FormB:
Code:
If Me.OpenArgs & "" <> "" Then
    Me.PhoneID.DefaultValue = Me.OpenArgs
End If

Duane
Hook'D on Access
MS Access MVP
 
Thank you Duane! This works perfectly. I have searched and searched for an answer to this online. Many people have the same problem, but I couldn't find an answer until you provided it.

Thank you very much,
Sophia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top