I need help resolving a data entry problem.
I have a main form (ECMR_Main), where on the Patient's tab of the main form, allows selecting a patient from a list box that is associated with the table Tbl_PT_Demographics that contains patient demographic data.
On the Patient's tab of the main form there is a command button for entering a new patient in to the table Tbl_PT_Demographics. When the command button is clicked on, its "On-Click" command contains the code to:
1) Changes a subform SubFrm_PT_Demographic_Data from hidden to visible
2) Creates the new patient record in the table Tbl_PT_Demographics.
This is the code:
- - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub Cmd_Add_New_Patient_Click()
On Error GoTo Err_Cmd_Add_New_Patient_Click
' On Add New Patient insure that the Patient Data subform is visible
SubFrm_PT_Demographic_Data= True
' Create New Record for the New Patient to be entered in to the Database
DoCmd.GoToRecord , , acNewRec
Exit_Cmd_Add_New_Patient_Click:
Exit Sub
Err_Cmd_Add_New_Patient_Click:
MsgBox Err.Description
Resume Exit_Cmd_Add_New_Patient_Click
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - -
OK. The problem is that when one enters the first character of a new patient's name I get the error message:
"You tried to assign the Null value to a variable that is not a variant data type."
If one clicks OK on the error message window it disapears and the character entered appears in the text box. One can then continue to add data and save the new patient's demographic data.
Placing this line of code
' Set Focus to the Patient Demographic Data Subform
[SubFrm_PT_Demographic_Data].SetFocus
before the DoCmd resolves the above error message.
However, . . . when one goes to save the new patient's demographic data the error message:
"The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again."
appears. And just won't go away. No matter how many times one clicks on its "OK".
No there are no duplicate index, key, etc. entries. It appears to be something specifically related to and where the Set Focus line of code is placed. If it is placed any where else one gets the first error message.
If one is merely changing the demographic data of an exising patient every thing works quite nicely. This uses the same subform and the Save New/Changed Patient Data command button's code as the Add New Patient.
Here is the Save New/Changed Patient Data command button code.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub Cmd_Save_Patient_Data_Click()
On Error GoTo Err_Cmd_Save_Patient_Data_Click
' Save New Patient record
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Forms![Frm_ECMR_Main].Requery
' After Save New/Changed Patient insure that the Patient Data subform is invisible
SubFrm_PT_Demographic_Pacemaker_ICD_Device_Data.Visible = False
[ListBox_Display_Patients].SetFocus
[ListBox_Display_Patients].Requery
[ListBox_Display_Patients].Selected(0) = True
[ListBox_Display_Patients].SetFocus
' Display All Patients in the Database
ButtonLetter = "*"
' Now search for all patient last names that start with this letter
Call Find_A_Letter
' Refresh the form so that the list of patients are displayed in the ListBox
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Exit_Cmd_Save_Patient_Data_Click:
Exit Sub
Err_Cmd_Save_Patient_Data_Click:
MsgBox Err.Description
Resume Exit_Cmd_Save_Patient_Data_Click
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The specific Details:
The main form ECMR_Main is associated with the table Tbl_PT_Demographics. The table has a primary index/key. There are other tables that are linked to it in a one to many relationship.
The subform SubFrm_PT_Demographic_Data on the main form ECMR_Main has the parent-child relationship setup. The parent is the table Tbl_PT_Demographics. The subform uses the same table name for the child because its data is saved to that table.
Why is this set up this way? My thinking was that the subform would not be visible unless a new patient was being added or there were changes that needed to be made to an existing patient's demographic data. Once a new patient was added or an existing patient's data changed, on saving the data, the subform is set to invisible again. This same philosophy is used on other tab pages of the main form where data is entered through a subform and saved in to another table that is related to the main table in a one to many relationship.
Now:
1) Is there an inheirent problem with a subform on a mainform where the subform's Parent and Child definition are the same table name?
2) Is there something else that needs to be added to the Add New Patient or the Save New Patient command button code?
3) Should I be doing this, code wise, differently?
4) Or, I could just put the new patient data entry text/combo boxes, etc. back on to the main form instead of being on a subform. That did work quite nicely before I decided to change it to a main-subform format.
Anyone have a solution or any ideas on how to resolve this problem?
Best Regards,
I have a main form (ECMR_Main), where on the Patient's tab of the main form, allows selecting a patient from a list box that is associated with the table Tbl_PT_Demographics that contains patient demographic data.
On the Patient's tab of the main form there is a command button for entering a new patient in to the table Tbl_PT_Demographics. When the command button is clicked on, its "On-Click" command contains the code to:
1) Changes a subform SubFrm_PT_Demographic_Data from hidden to visible
2) Creates the new patient record in the table Tbl_PT_Demographics.
This is the code:
- - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub Cmd_Add_New_Patient_Click()
On Error GoTo Err_Cmd_Add_New_Patient_Click
' On Add New Patient insure that the Patient Data subform is visible
SubFrm_PT_Demographic_Data= True
' Create New Record for the New Patient to be entered in to the Database
DoCmd.GoToRecord , , acNewRec
Exit_Cmd_Add_New_Patient_Click:
Exit Sub
Err_Cmd_Add_New_Patient_Click:
MsgBox Err.Description
Resume Exit_Cmd_Add_New_Patient_Click
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - -
OK. The problem is that when one enters the first character of a new patient's name I get the error message:
"You tried to assign the Null value to a variable that is not a variant data type."
If one clicks OK on the error message window it disapears and the character entered appears in the text box. One can then continue to add data and save the new patient's demographic data.
Placing this line of code
' Set Focus to the Patient Demographic Data Subform
[SubFrm_PT_Demographic_Data].SetFocus
before the DoCmd resolves the above error message.
However, . . . when one goes to save the new patient's demographic data the error message:
"The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again."
appears. And just won't go away. No matter how many times one clicks on its "OK".
No there are no duplicate index, key, etc. entries. It appears to be something specifically related to and where the Set Focus line of code is placed. If it is placed any where else one gets the first error message.
If one is merely changing the demographic data of an exising patient every thing works quite nicely. This uses the same subform and the Save New/Changed Patient Data command button's code as the Add New Patient.
Here is the Save New/Changed Patient Data command button code.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub Cmd_Save_Patient_Data_Click()
On Error GoTo Err_Cmd_Save_Patient_Data_Click
' Save New Patient record
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Forms![Frm_ECMR_Main].Requery
' After Save New/Changed Patient insure that the Patient Data subform is invisible
SubFrm_PT_Demographic_Pacemaker_ICD_Device_Data.Visible = False
[ListBox_Display_Patients].SetFocus
[ListBox_Display_Patients].Requery
[ListBox_Display_Patients].Selected(0) = True
[ListBox_Display_Patients].SetFocus
' Display All Patients in the Database
ButtonLetter = "*"
' Now search for all patient last names that start with this letter
Call Find_A_Letter
' Refresh the form so that the list of patients are displayed in the ListBox
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Exit_Cmd_Save_Patient_Data_Click:
Exit Sub
Err_Cmd_Save_Patient_Data_Click:
MsgBox Err.Description
Resume Exit_Cmd_Save_Patient_Data_Click
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The specific Details:
The main form ECMR_Main is associated with the table Tbl_PT_Demographics. The table has a primary index/key. There are other tables that are linked to it in a one to many relationship.
The subform SubFrm_PT_Demographic_Data on the main form ECMR_Main has the parent-child relationship setup. The parent is the table Tbl_PT_Demographics. The subform uses the same table name for the child because its data is saved to that table.
Why is this set up this way? My thinking was that the subform would not be visible unless a new patient was being added or there were changes that needed to be made to an existing patient's demographic data. Once a new patient was added or an existing patient's data changed, on saving the data, the subform is set to invisible again. This same philosophy is used on other tab pages of the main form where data is entered through a subform and saved in to another table that is related to the main table in a one to many relationship.
Now:
1) Is there an inheirent problem with a subform on a mainform where the subform's Parent and Child definition are the same table name?
2) Is there something else that needs to be added to the Add New Patient or the Save New Patient command button code?
3) Should I be doing this, code wise, differently?
4) Or, I could just put the new patient data entry text/combo boxes, etc. back on to the main form instead of being on a subform. That did work quite nicely before I decided to change it to a main-subform format.
Anyone have a solution or any ideas on how to resolve this problem?
Best Regards,