B
blobb
Hopefully I will be clear about what I am attempting to accomplish here.
I have a tabbed control with two main subforms [Index Form] and [Pregnancy],
and [Pregnancy] has 7 tabbed subforms. When a number is entered into the
first main subform [Index Form]!PregNum, I want to automatically create the
number of pregnancies in the 7 subforms of the [Pregnancy] subform. I found
some code online that looked as though it would automatically create the
records in the Pregnancy table (where the [Pregnancy] form & pregnancy 7
subforms are looking for their data). This code seems to be working up to
the point of requerying the subform and/or subforms(s). After the code runs
(from the “Create Pregnancies†button on the [Index Form]!) I attempt to go
to the [Pregnancy] tab, and get this error: Invalid Entry. I looked at the
IndexCase table and the Pregnancy table and both tables say that PregID are
indexed as “YES (Duplicates OK)â€. Am I missing a major error in my
thought/coding process? Any help would be appreciated! Attached is the code
that I am attempting to use.
Private Sub Create_Records_Click()
Dim db As Database
Dim LSQL As String
Dim PregCntr As Integer
Dim PregNum As Integer
Dim pfrm As Object
'Establish connection to current database
Set db = CurrentDb()
PregCntr = 1
PregNum = Forms![Contacts Display]![Index Form]!PregNum
'Create SQL to insert item numbers 1 to PregNum into table pregnancy
Do Until PregCntr = PregNum
LSQL = "insert into pregnancy (ContactID, IndexID, PregID)"
LSQL = LSQL & " values ("
LSQL = LSQL & "'" & ContactID & "', ‘" & "'" & IndexID & "', " &
PregCntr & ")"
'Perform SQL
db.Execute LSQL
'Increment counter variable
PregCntr = PregCntr + 1
Loop
'Requery subform that new records are listing
Forms![Contacts Display]![Pregnancy].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - Course Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - Diamox Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - General Preg
Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - IH After
Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - MedSurg Interventions
Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - Newborn Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - Present Status
Subform].Requery
End Sub
I have a tabbed control with two main subforms [Index Form] and [Pregnancy],
and [Pregnancy] has 7 tabbed subforms. When a number is entered into the
first main subform [Index Form]!PregNum, I want to automatically create the
number of pregnancies in the 7 subforms of the [Pregnancy] subform. I found
some code online that looked as though it would automatically create the
records in the Pregnancy table (where the [Pregnancy] form & pregnancy 7
subforms are looking for their data). This code seems to be working up to
the point of requerying the subform and/or subforms(s). After the code runs
(from the “Create Pregnancies†button on the [Index Form]!) I attempt to go
to the [Pregnancy] tab, and get this error: Invalid Entry. I looked at the
IndexCase table and the Pregnancy table and both tables say that PregID are
indexed as “YES (Duplicates OK)â€. Am I missing a major error in my
thought/coding process? Any help would be appreciated! Attached is the code
that I am attempting to use.
Private Sub Create_Records_Click()
Dim db As Database
Dim LSQL As String
Dim PregCntr As Integer
Dim PregNum As Integer
Dim pfrm As Object
'Establish connection to current database
Set db = CurrentDb()
PregCntr = 1
PregNum = Forms![Contacts Display]![Index Form]!PregNum
'Create SQL to insert item numbers 1 to PregNum into table pregnancy
Do Until PregCntr = PregNum
LSQL = "insert into pregnancy (ContactID, IndexID, PregID)"
LSQL = LSQL & " values ("
LSQL = LSQL & "'" & ContactID & "', ‘" & "'" & IndexID & "', " &
PregCntr & ")"
'Perform SQL
db.Execute LSQL
'Increment counter variable
PregCntr = PregCntr + 1
Loop
'Requery subform that new records are listing
Forms![Contacts Display]![Pregnancy].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - Course Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - Diamox Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - General Preg
Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - IH After
Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - MedSurg Interventions
Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - Newborn Subform].Requery
Forms![Contacts Display]![Pregnancy]![Pregnancy - Present Status
Subform].Requery
End Sub