Why are there duplicate names in SENDER table? Are KABITA DALAL and KABITA DEVI really so common? Name parts should be separate fields. The SENDER_NAME field in Registration should be number type because the ID field in SENDER is autonumber. Primary and foreign key fields must be same type to allow joins in queries. You have Lookup set in table, suggest you not do that http://access.mvps.org/access/lookupfields.htm.
Is address info in Registration the address of sender? That info should be in SENDER table. Why is PIN saved in Registration? This is duplicating data.
'Name' is a reserved word. Should not use reserved words as names for anything, especially for fields. This is causing confusion in Access when you reference field named Name because Name is a property. Reserved words used as names must be enclosed in [], however, event that doesn't fix this issue. Rename the field in SENDER table. When I did the name change, Access would not recognize the field/textbox on SENDER form. I deleted then recreated the textboxes and then Access recognized the field.
Need to open the SENDER form to a new record. DoCmd.OpenForm ("SENDER"), , , , acFormAdd
Need code behind the SENDER form to save record and requery the combobox on Registration form.
Also should avoid spaces in names.
Every module should have these 2 lines in header:
Option Compare Database
Option Explicit
The gbl_exit_name = False line is not explained by the tutorial and doesn't seem relevant so comment it out or delete.
Code behind Registration:
Code:
Option Compare Database
Option Explicit
Private Sub Sender_Name_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue
Call Sender_Name_Not_Found(NewData)
End Sub
Public Sub Sender_Name_Not_Found(NewData)
Dim ans As Variant
' new Name
'gbl_exit_name = False
ans = MsgBox("Do you want to add this Name?", _
vbYesNo, "Add New Name?")
If ans = vbNo Then
Me.SENDER_NAME = Null
DoCmd.GoToControl "Sender_Name"
GoTo exit_it
End If
' add Name
DoCmd.OpenForm ("SENDER"), , , , acFormAdd
Form_SENDER.SENDER_NAME = NewData
DoCmd.GoToControl "PIN"
Me.SENDER_NAME = Null
Me.HOUSE_NUMBER.SetFocus
exit_it:
End Sub
Code behind command button on Sender:
Code:
Option Compare Database
Option Explicit
Private Sub btnClose_Click()
If CurrentProject.AllForms("Registered Letters").IsLoaded Then
[Form_Registered Letters].[SENDER_NAME].Requery
End If
DoCmd.Close
End Sub
Might want to set the Sender form Cycle property to CurrentRecord.