Please help,
Im new to this but im trying hard.
Ive looked at numerous resources but couldn't seem to get it to work. I have an Access database where Im trying to search a table(servicecenterproblem) for a matching !me form entry(number) in the field (number).
If theres a match then msg "dup entry", if no match then add.number to field.
Here is my sub code.
Private Sub runtest_Click()
If IsNull(Me!number) Then
MsgBox "Service Number is a Required Entry.", 48
Me!number.SetFocus
Else
'**** add a new record ****
Dim CurConn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim CurDB As Database
Set CurDB = CurrentDb
Set CurConn = New ADODB.Connection
With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source= " & CurDB.Name
.Open
End With
Set rst = New ADODB.Recordset
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.Open "ServiceCenterProblem",CurConn, , ,adCmdTableDirect
rst.Find ("number = '[ME!number]'"
, MoveFirst, adSearchForward
If Not rst.EOF Then
MsgBox "Service Number is a Duplicate Entry.", 48
Me!number.SetFocus
Else
With rst
.AddNew
![number] = (Me!number)
.Update
MsgBox Me!number & " has been added to the Service Center Table."
End With
End If
Set rst = Nothing
Set cnn = Nothing
Exit Sub
End If
End Sub
Im new to this but im trying hard.
Ive looked at numerous resources but couldn't seem to get it to work. I have an Access database where Im trying to search a table(servicecenterproblem) for a matching !me form entry(number) in the field (number).
If theres a match then msg "dup entry", if no match then add.number to field.
Here is my sub code.
Private Sub runtest_Click()
If IsNull(Me!number) Then
MsgBox "Service Number is a Required Entry.", 48
Me!number.SetFocus
Else
'**** add a new record ****
Dim CurConn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim CurDB As Database
Set CurDB = CurrentDb
Set CurConn = New ADODB.Connection
With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source= " & CurDB.Name
.Open
End With
Set rst = New ADODB.Recordset
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.Open "ServiceCenterProblem",CurConn, , ,adCmdTableDirect
rst.Find ("number = '[ME!number]'"
If Not rst.EOF Then
MsgBox "Service Number is a Duplicate Entry.", 48
Me!number.SetFocus
Else
With rst
.AddNew
![number] = (Me!number)
.Update
MsgBox Me!number & " has been added to the Service Center Table."
End With
End If
Set rst = Nothing
Set cnn = Nothing
Exit Sub
End If
End Sub