Wayne
Hi Wayne
a really weird thing is happening to my code.
I declared multiple recordsets in my sub, and used them, and somehow it suddenly all worked properly.
Then, all of a sudden, it decided not to load the recordsets anymore.
eg. the following code gives rstLC!LO1_ID an integer value which it gets from rst1!LO_ID - but when i run this block of code it gives me a run time error because rstLC!LO1_ID is not loading the integer.
' Get LO1_ID value from recordset rst1
rstLC!LO1_ID = rst1!LO_ID
rst1!LO_ID loads its integer inmthe following manner:
rst1!LO_ID = DMax("LO_ID", "[Learning Outcomes]") + 1
so why is it not storing a value??
If I do this code below: rst1!LO_ID stores the correct integer...but i dont understand why the above code, which worked yesterday morning, has suddenly decided not to work now??
Dim y As Integer
y = DMax("LO_ID", "[Learning Outcomes]") + 1
rst1!LO_ID = y
This is a copy of the entire code in this sub. I think it just wants to eat me
Bella
----------------------------------------------------------------------------------
Private Sub Step1cmd_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim rst3 As DAO.Recordset
Dim rst4 As DAO.Recordset
Dim rst5 As DAO.Recordset
Dim rst6 As DAO.Recordset
Dim rstLC As DAO.Recordset
Dim sql As String
Dim sql2 As String
Dim strSQL As String
Set dbs = CurrentDb
'Build an SQL string that selects fields from the Subject List table to update to.
sql = "SELECT [Subject List].[SL_ID], [Subject List].[Subject Name], " & _
"[Subject List].[Year_ID], [Subject List].[KLA_ID] " & _
"FROM [Subject List];"
Set rst = dbs.OpenRecordset(sql)
rst.AddNew
' Get next number
rst!SL_ID = DMax("SL_ID", "[Subject List]") + 1
' Get Subject Name value from text box & put this value into the recordset
rst![Subject Name] = Me.subject
' Get Kla value from kla combo box & put this value into the recordset
rst!KLA_ID = Me.kla
' Get Year_ID value from year combo box & put this value into the recordset
rst!Year_ID = Me.cboyear
' ------------------------------------------------------------------------------
'Build an SQL string that selects fields from the Learning Outcomes Table
sql2 = "SELECT [Learning Outcomes].[LO_ID], [Learning Outcomes].[Learning Outcomes] " & _
"FROM [Learning Outcomes];"
Set rst1 = dbs.OpenRecordset(sql2)
Set rst2 = dbs.OpenRecordset(sql2)
Set rst3 = dbs.OpenRecordset(sql2)
Set rst4 = dbs.OpenRecordset(sql2)
Set rst5 = dbs.OpenRecordset(sql2)
Set rst6 = dbs.OpenRecordset(sql2)
rst1.AddNew
rst2.AddNew
rst3.AddNew
rst4.AddNew
rst5.AddNew
rst6.AddNew
' Get Next LO_ID in Learning Outcomes Table
rst1!LO_ID = DMax("LO_ID", "[Learning Outcomes]") + 1
rst2!LO_ID = DMax("LO_ID", "[Learning Outcomes]") + 2
rst3!LO_ID = DMax("LO_ID", "[Learning Outcomes]") + 3
rst4!LO_ID = DMax("LO_ID", "[Learning Outcomes]") + 4
rst5!LO_ID = DMax("LO_ID", "[Learning Outcomes]") + 5
rst6!LO_ID = DMax("LO_ID", "[Learning Outcomes]") + 6
' Get Learning Outcomes value from text box
rst1![Learning Outcomes] = Me.txtLO1
rst2![Learning Outcomes] = Me.txtLO2
rst3![Learning Outcomes] = Me.txtLO3
rst4![Learning Outcomes] = Me.txtLO4
rst5![Learning Outcomes] = Me.txtLO5
rst6![Learning Outcomes] = Me.txtLO6
' Update the loaded recordset to the Learning Outcomes table
rst1.Update
rst2.Update
rst3.Update
rst4.Update
rst5.Update
rst6.Update
' --------------------------------------------------------------------------------------
' Build string to fill in the [Learning Outcomes Connector]
strSQL = "SELECT [Learning Outcomes Connector].SL_ID, [Learning Outcomes Connector].LO1_ID, " & _
"[Learning Outcomes Connector].LO2_ID, [Learning Outcomes Connector].LO3_ID, " & _
"[Learning Outcomes Connector].LO4_ID, [Learning Outcomes Connector].LO5_ID, " & _
"[Learning Outcomes Connector].LO6_ID, [Learning Outcomes Connector].LO_Counter " & _
"FROM [Learning Outcomes Connector];"
Set rstLC = dbs.OpenRecordset(strSQL)
rstLC.AddNew
' Get next SL_ID for the Learning Outcomes Connector Table
rstLC!SL_ID = rst!SL_ID
' Get LO1_ID value from recordset rst1
rstLC!LO1_ID = rst1!LO_ID
' Get LO2_ID value from recordset rst2
rstLC!LO2_ID = rst2!LO_ID
' Get LO3_ID value from recordset rst3
rstLC!LO3_ID = rst3!LO_ID
' Get LO4_ID value from recordset rst4
rstLC!LO4_ID = rst4!LO_ID
' Get LO5_ID value from recordset rst5
rstLC!LO5_ID = rst5!LO_ID
' Get LO6_ID value from recordset rst6
rstLC!LO6_ID = rst6!LO_ID
' Assign random LO_Count value into the recordset
rstLC!LO_Counter = 55
' Update the loaded recordset to the learning Outcomes Connector table
rstLC.Update
' Update the loaded recordset to the Subject List table
rst.Update
End Sub
