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

Right Code / Wrong Code???

Status
Not open for further replies.

Tofias1

MIS
Jun 17, 2002
57
US
My DB is almost complete except for this code.

Private Sub Form_Current()
Dim one As String
Dim Two As String
one = Me.Text5.Value

If Me.Text5.Value = True Then
Me.main.Value = one
one = "0" 'Thought this would clear the value of one????
Else
Me.main.Value = "0"

End If

End Sub


'code resides behind sub form

It works fine until I try to add a new record. The form is linked to a query so the value of the text can grab the info that it needs from the main table. It would probably help if I told you that this is to grab the primary key from the main table and update it automaticaly to this form when the cmd button is clicked to bring the user to the secondary form (data for both forms are from 2 diff tables). (Hope that is not to confusing). The error that is generated is from Access and not VB. If the new record is saved and the form is shut down then the secondary form saves the fields info. to the table but once a new record is entered in the main form and the cmd clicked it will not work generating the error "You can not add or change the data because a related record is required in the main table" Now why would this happen if the records stored are the same and are not changing? The DB is in 3rd normal form, however when I delete the relationships it works everytime. Any Help would be greatly appreciated. Sorry in advance if my question is to confusing.
 
once a new record is entered in the main form and the cmd clicked it will not work generating the error "You can not add or change the data because a related record is required in the main table"

Access saves the records to disk when the form closes. If you call another form and the form containing the new data is not closed it is not saved - thus an error.

You can prevent this error by adding to the command button that opens the new form

Docmd.RunCommand acCmdSaveRecord

This forces a write to disk and will then avoid the related record error.

HTH
 
Hey thank you for the reply. It was greatly appreciated.

RAD.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top