Hi,
I have a form based on the member information, which has a individual_Id has a field and primary key for that table.
I am trying to code, so that if a ID is already present in the table, give user a message box, saying that the ID already exists, enter a new ID. And again it has to focus on the control txt_Individual ID, so that they know they have to enter the ID without moving on.
The problem with my code is it gives the error message, but focuses to the next control instead of the control I said to focus on.
I am just going nuts.
I have the code in the before update event of the
txtIndividual_ID:
My code is:
Private Sub txtIndividual_ID_AfterUpdate()
Dim db As Database
Dim rs As Recordset
Dim Ssql As String
Dim selectedid As Integer
If Not IsNull(Me.txtIndividual_ID) And Me.txtIndividual_ID <> 0 Then
selectedid = Me.txtIndividual_ID
Else
MsgBox "There is no such Individual_Id ", vbCritical
Me.txtIndividual_ID = 0
Me.txtIndividual_ID.SetFocus
Exit Sub
End If
Set db = CurrentDb
Ssql = " SELECT Individual_id FROM tblMemberInformation WHERE" _
& " Individual_id IN(" & selectedid & ")"
Set rs = db.OpenRecordset(Ssql, 8)
If Not rs.EOF Then
MsgBox "This Individual_id already exist Please enter a different ID", vbCritical
Me.txtIndividual_ID = 0
Me.txtIndividual_ID.SetFocus
Exit Sub
End If
Me.LstCommitee.Requery
rs.Close
Set rs = Nothing
End Sub
I did all the possible changes I could do, But it did'nt help me.
Thanks alot in advance
Regards
I have a form based on the member information, which has a individual_Id has a field and primary key for that table.
I am trying to code, so that if a ID is already present in the table, give user a message box, saying that the ID already exists, enter a new ID. And again it has to focus on the control txt_Individual ID, so that they know they have to enter the ID without moving on.
The problem with my code is it gives the error message, but focuses to the next control instead of the control I said to focus on.
I am just going nuts.
I have the code in the before update event of the
txtIndividual_ID:
My code is:
Private Sub txtIndividual_ID_AfterUpdate()
Dim db As Database
Dim rs As Recordset
Dim Ssql As String
Dim selectedid As Integer
If Not IsNull(Me.txtIndividual_ID) And Me.txtIndividual_ID <> 0 Then
selectedid = Me.txtIndividual_ID
Else
MsgBox "There is no such Individual_Id ", vbCritical
Me.txtIndividual_ID = 0
Me.txtIndividual_ID.SetFocus
Exit Sub
End If
Set db = CurrentDb
Ssql = " SELECT Individual_id FROM tblMemberInformation WHERE" _
& " Individual_id IN(" & selectedid & ")"
Set rs = db.OpenRecordset(Ssql, 8)
If Not rs.EOF Then
MsgBox "This Individual_id already exist Please enter a different ID", vbCritical
Me.txtIndividual_ID = 0
Me.txtIndividual_ID.SetFocus
Exit Sub
End If
Me.LstCommitee.Requery
rs.Close
Set rs = Nothing
End Sub
I did all the possible changes I could do, But it did'nt help me.
Thanks alot in advance
Regards