AshikHusein
Registered User.
- Local time
- Today, 13:18
- Joined
- Feb 7, 2003
- Messages
- 147
I keep on getting an error message with the code below. What I am basically trying to do is to save a newly entered record on a form. This works well with DAO but now I am trying to convert all my code to ADO for future migration to SQL.
The error # is errror 2501 which says something to the effect that "the save action was cancelled". I have been trying to figure this out for the last 2 days but I cannot see where the problem lies. The code is as follows:
Would appreciate help with this or help with error# 2501 and what this error is all about. Thank you.
The error # is errror 2501 which says something to the effect that "the save action was cancelled". I have been trying to figure this out for the last 2 days but I cannot see where the problem lies. The code is as follows:
Code:
Private Sub Command32_Click()
'This procedure prevents the the new form from being saved if one of the required fields is not entered.
Dim ddrec As New ADODB.Recordset
Set Curdb = CurrentDb
Set curconn = New ADODB.Connection
With curconn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source= " & Curdb.Name
.Open
End With
'On Error GoTo error_proc_cmd32
If [ddown_qty] = 0 Or IsNull([ddown_date]) Or IsNull([IPO_name]) Or IsNull([ddown_time]) Then
If MsgBox("A required field(s) was not completed." & vbCrLf & "This order will not be saved.", vbOKCancel) = vbCancel Then
' if the user clicks CANCEL then set the dummy1 field to null. This was updated to 1 to lock the record
strselect = "SELECT s.* "
strfrom = "FROM tbl_init_IPO_entry_details s "
strwhere = "WHERE s.IPO_name = """ & IPO_name & """"
searchSTR = strselect & strfrom & strwhere
Set ddrec = New ADODB.Recordset
ddrec.CursorType = adOpenKeyset
ddrec.Open searchSTR, curconn, adOpenKeyset
ddrec![dummy1] = Null
ddrec.Update
'if user cliks "Cancel" then two esc keys are sent to ensure that entries are cleared
DoCmd.RunMacro "mcr_send_2_keys_esc"
'clear these info labls for a fresh entry
[Label37].Visible = False
[Label38].Visible = False
[IPO_name].Locked = False
Else
'if user clicks OK, then the sub ends and user may correct entries and repeat the procedure
Exit Sub
End If
Else
[userid].SetFocus 'these 3 lines of procedure are to ensure that the userid gets updated
[userid].Locked = False 'removes the lock on the userid control
[userid].Text = fOSUserName
'if all entries are good, then the form is saved and moved on to the next record for a new entry
DoCmd.Save acForm, "frm_IPO_ddown" --> THE ERROR 2501 OCCURS HERE
Set ddrec = Nothing
strselect = "SELECT s.* "
strfrom = "FROM tbl_init_IPO_entry_details s "
strwhere = "WHERE s.IPO_name = """ & IPO_name & """"
searchSTR = strselect & strfrom & strwhere
Set ddrec = New ADODB.Recordset
ddrec.CursorType = adOpenKeyset
ddrec.LockType = adLockPessimistic
ddrec.Open searchSTR, curconn, adOpenKeyset
ddrec![dummy1] = Null
ddrec.Update
ddrec.Close
Set ddrec = Nothing
DoCmd.GoToRecord acDataForm, "frm_IPO_ddown", acNewRec
MsgBox ("Drawdown quantity has been updaed")
Set curconn = Nothing
Exit Sub
'error_proc_cmd32:
'MsgBox ("You tried to edit the IPO name. You cannot do that!")
'DoCmd.RunMacro "mcr_send_2_keys_esc"
End If
End Sub
Would appreciate help with this or help with error# 2501 and what this error is all about. Thank you.
Last edited by a moderator: