Value passing

  • Thread starter Thread starter Rpettis31
  • Start date Start date
R

Rpettis31

I have a form that can generate another form with some of the data going to
the new form. The new form generates a new ID number which I want to retain
on the original form.

I tried this code line to get that result but I end up with an error-
!txtCarId = "CAR" & IdCar

txtCarId is on the first form -- IdCar is the value of the form that was
created I want on the original form..

Private Sub CAR_Click()
' Open CAR form to add new record
DoCmd.OpenForm "frmCar", DataMode:=acFormAdd

'Fill in corresponding information
With Forms!frmCar
!IssueId = "DMR-" & Me.DMRID
!ItemNumber = Me.ItemNumber
!ProblemDescription = Me.ProblemDescription
'!Description = Me.ItemDescription
!txtCarId = "CAR" & IdCar
End With

'Close Form
DoCmd.Close acForm, Me.Name, acSaveNo
 
It is important to realize the forms do not contain data! They only
give you a convenient way to look at data stored in tables. If all you
are doing is creating a new record, then add it to the table directly.

for instance:

'~~~~~~~~~~~~~~~~
dim db as dao.database _
, r As DAO.Recordset

set db = Currentdb

set r = db.OpenRecordset("YourTablename", dbOpenDynaset)

r.AddNew
r!Fieldname1 = value
r!Fieldname2 = value
'etc
r.update

r.close
set r = nothing

set db = nothing
'~~~~~~~~~~~~~~~~

BUT! If you already have fields with information in one table, you
should not be storing the same information in another table. Read this:

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace


Warm Regards,
Crystal

*
(: have an awesome day :)
*
 
Both forms are bound to tables. The forms are used to collect data. I am
not trying to violate normalization rules only list the reference to the new
form's id.
 
"Both forms are bound to tables. "

I understand ... but it looks like you are opening another form ONLY to
add a record, and then you are closing it -- just suggesting a better
way to accomplish the same task

Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day :)
*
 
Back
Top