G
Guest
Greetings all. I am using ADP 2003 and SQL2K. I have a form with a stored
procedure as the record source. There is a search form where users type in a
job number that is passed to the procedure to bring up the record
corresponding to that job number. The job number is the PK of the table
called by the stored procedure. The problem is when users search for a job
that is not in the system a blank form is displayed, and then when they try
to leave the form or hit the button to search for another job they get an
error saying 'can not insert null value into table...' This is easily fixed
by hitting the escape key on the keyboard, but I would like for a new record
to not be started. Is it possible to return a message saying record does not
exist rather than start a new record? I currently have the following on the
forms txtJobNumber before update event to alert users that the number already
exists, in the event they did not search for it first.
Private Sub txtJobNumber_BeforeUpdate(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rstbljob_info As ADODB.Recordset
Dim strSQL As String
Dim boolDupId As Boolean
strSQL = "Select ewo FROM tbljob_info where ewo = '" & Form.[txtJobNumber] &
"'"
boolDupId = False
Set rstbljob_info = New ADODB.Recordset
Set cn = Application.CurrentProject.Connection
rstbljob_info.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
If Not rstbljob_info.EOF Then
boolDupId = True
MsgBox "The Job Number you entered already exists.", vbExclamation
End If
rstbljob_info.Close
Cancel = boolDupId
End Sub
I am not sure exactly how this works, as I found it on the Microsoft help
site and used my table and field names. I think the jist of it is that it
creates a select string based on the text box entry, and if the text entry is
not the end of the returned recordset it knows the record already exists?
Where could I put something like this to stop a new record from being created
when the job number being searched for does not exist. Thank you, and please
let me know what else I need to impart, as I am not sure where I need to
start.
procedure as the record source. There is a search form where users type in a
job number that is passed to the procedure to bring up the record
corresponding to that job number. The job number is the PK of the table
called by the stored procedure. The problem is when users search for a job
that is not in the system a blank form is displayed, and then when they try
to leave the form or hit the button to search for another job they get an
error saying 'can not insert null value into table...' This is easily fixed
by hitting the escape key on the keyboard, but I would like for a new record
to not be started. Is it possible to return a message saying record does not
exist rather than start a new record? I currently have the following on the
forms txtJobNumber before update event to alert users that the number already
exists, in the event they did not search for it first.
Private Sub txtJobNumber_BeforeUpdate(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rstbljob_info As ADODB.Recordset
Dim strSQL As String
Dim boolDupId As Boolean
strSQL = "Select ewo FROM tbljob_info where ewo = '" & Form.[txtJobNumber] &
"'"
boolDupId = False
Set rstbljob_info = New ADODB.Recordset
Set cn = Application.CurrentProject.Connection
rstbljob_info.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
If Not rstbljob_info.EOF Then
boolDupId = True
MsgBox "The Job Number you entered already exists.", vbExclamation
End If
rstbljob_info.Close
Cancel = boolDupId
End Sub
I am not sure exactly how this works, as I found it on the Microsoft help
site and used my table and field names. I think the jist of it is that it
creates a select string based on the text box entry, and if the text entry is
not the end of the returned recordset it knows the record already exists?
Where could I put something like this to stop a new record from being created
when the job number being searched for does not exist. Thank you, and please
let me know what else I need to impart, as I am not sure where I need to
start.