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!

Form is not saving--dont know why!!! HELP!!!!

Status
Not open for further replies.

bgibsonIYD

Technical User
Jun 18, 2001
28
US
I have a registration databaase that I am creating. It was working fine until Tuesday--then saving the records went haywire. I have the database set up like this:

Form Main address has all the contact's information, then it has a "Register" button on it, where the Registration form opens. The Registration form corresponds with the main address form with [NAME ID]. The relationships are set up correctly, and in the Registration form, the filter on the Registration form is [NAME ID] to pull the record that it corresponds to in the Main address form.

The main address for is letting me enter the record, and letting me press the "Register" button, but it give's me an error message "Does not have a related record in the Names table". Why is this happening?????? How can I fix it? We have looked at everything, and apparently we are looking over something. Can anyone help?
Beth
**Learning Access**
 
If you could post some code examples or something I might be able to help
 
The following is the code that I have on the "OnClick" event of the Register button on the Main address form. Is there any other code that you need?


Private Sub cmdRegister_Click()
On Error GoTo Err_cmdRegister_Click

Dim Value1, Value2 As String


If IsNull(Me![NAME ID]) Then
MsgBox "Enter contact's information before registering them."
DoCmd.GoToControl "[FIRST NAME]"
ElseIf IsNull(Me![SSN#]) Then
MsgBox "Social Security # must be entered before you can register this person"
DoCmd.GoToControl "[SSN#]"
Else
DoCmd.Save acForm, "Main Address"
DoCmd.OpenForm "Registration"

DoCmd.OpenForm "Registration", , , "[NAME ID] = " & Me.NAME_ID
Value1 = Me.FIRST_NAME
Value2 = Me.LAST_NAME
Forms![Registration]![NAME] = Value1 & " " & Value2
End If

Exit_cmdRegister_Click:
Exit Sub

Err_cmdRegister_Click:
MsgBox Err.Description
Resume Exit_cmdRegister_Click

End Sub
Beth
**Learning Access**
 
This usually happens where you are adding data to a table which is related on a 1 to Many basis with another table. If you add a record to the Many table and there is no corresponding record in the 1 table, you will get this error.

This can also happen if you try to add a record without a Foreign Key (i.e. the value that is linked to the Primary Key in the main table.

I am not sure if you have such setup (i.e. 2 tables with a one to many relationship) and in fact it does not soudn like it from your description. The only other thing I can think of is that when you open your "Register" table the current record is not being pulled in correctly. I have never used "Me.FieldName" in the OpenForm argument as it has never worked for me. I have always had to refer to a control, e.g. a text box, e.g. "[NAME ID] = Forms![frmMain]![txtNameID]" and this always works.

Sorry I this is all a little confused - it is difficult to explain, but above are just some of my thoughts as to what might be happening.
Have fun! :eek:)

Alex Middleton
 
None of the above worked.

I have found that I can enter the information in the Main address form, and it saves, but I still get an error message saying "Microsoft Access might have encountered an error while trying to save a record. If you close this object now the data changes you made will be lost.Do you want to close the database object anyways?" It gives me this error, but the information is still saved.

Beth
**Learning Access**
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top