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

Saving a record to a table corrupts the table's index

Status
Not open for further replies.

DPROMICS

Technical User
Nov 5, 2003
108
US
I changed the following VB code so that the focus is set to the subform before the new record is created. All worked well before I added the line of code, except I received an error message: "You tried to assign the Null value to a variable that is not a variant data type". After clicking OK one could proceed to enter data for a new patient and save it.
______________________________________________________

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_Pacemaker_ICD_Device_Data.Visible = True

' Set Focus to the Patient Demographic Data Subform
[SubFrm_PT_Demographic_Pacemaker_ICD_Device_Data].SetFocus

' 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
__________________________________________________

Adding the set focus code resolved that error message but created a new problem. The problem is that now when I test the code the Tbl_PT_Demographics table's index gets screwed up when/after teh new record is saved. I have learned how to fix it teh database index problem. But, obviously not desirable to have that happen consistently.

Table: PT_Demographics is the primary table for this application and has a primary index key. Other tables are linked to this table in a one to many relationship.

The main form (Frm_ECMR_Main) has a subform (SubFrm_PT_Demographic_Pacemaker_ICD_Device_Data) where the new patient's demographic data is entered. Both forms use the same source, i.e. Tbl_PT_Demographics.

The subform is linked to the PT_Demographics table in a parent-child relationship via the table's primary key PT_DB_Index.

There is a command button labled: Add New Patient. The VB function below is executed by clicking on this command button.

I have tried recreating the add new patient command button and code, deleting the subform from the main form and adding it back again, etc. But the problem persists.

OK. Any thoughts as to why this is happening and more importantly how to prevent it from happening.

Best Regards,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top