G
Guest
Hi
i wish to popupulate the primary index field of a form with the highest value plus one (to increment the index- similar to 'autonumber'). The code i'm using is
Private Sub Form_Activate(
DoCmd.GoToRecord , , acNewRe
Dim nObservationId As Lon
Dim ObservationId As Long (this is the name of the text box to be populated
Dim sSqlStr2 As Strin
Dim oCurrentDb As Databas
Dim oRecSet As Recordse
Dim oField As Fiel
'** Determine the new ObservationId by finding the greatest +
sSqlStr2 = "SELECT MAX(tbl_Observation.ObservationId) + 1 AS 'ObservationId' FROM tbl_Observation
'** Attach to the database and run the above quer
Set oCurrentDb = currentd
Set oRecSet = oCurrentDb.OpenRecordset(sSqlStr2
'** Take the value from the open recordset's first column and populate the ObservationI
Set oField = oRecSet.Fields(0
nObservationId = oField.Valu
ObservationId = nObservationI
Me.Refres
End Su
Problem is that when the form opens the field is unpopulated despite the correct value being known throughout the code, consequently get an 'invalid use of null' when saving the contents of the form
Any ideas
Ta.
i wish to popupulate the primary index field of a form with the highest value plus one (to increment the index- similar to 'autonumber'). The code i'm using is
Private Sub Form_Activate(
DoCmd.GoToRecord , , acNewRe
Dim nObservationId As Lon
Dim ObservationId As Long (this is the name of the text box to be populated
Dim sSqlStr2 As Strin
Dim oCurrentDb As Databas
Dim oRecSet As Recordse
Dim oField As Fiel
'** Determine the new ObservationId by finding the greatest +
sSqlStr2 = "SELECT MAX(tbl_Observation.ObservationId) + 1 AS 'ObservationId' FROM tbl_Observation
'** Attach to the database and run the above quer
Set oCurrentDb = currentd
Set oRecSet = oCurrentDb.OpenRecordset(sSqlStr2
'** Take the value from the open recordset's first column and populate the ObservationI
Set oField = oRecSet.Fields(0
nObservationId = oField.Valu
ObservationId = nObservationI
Me.Refres
End Su
Problem is that when the form opens the field is unpopulated despite the correct value being known throughout the code, consequently get an 'invalid use of null' when saving the contents of the form
Any ideas
Ta.