Preventing ID Switching

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a combo box with student names in it. Each student name has a unique
ID attached "StudentID". If the current record ID belongs to student named
"Holly", I need to prevent the user from switching "Holly" to a different
student ID.

I have public variable which gets current value of StudentID:

Private Sub cboStudent_GotFocus()
Dim lngEmpID as Long
If Not IsNull(Me.cboStudent.Value) Then
lngEmpID = Me.cboStudent.Value
End If
End Sub

Now, I need to somehow compare value of lngEmpID to the changed value to see
if they match. If they dont match, I want to stop the ID switch.

How can i do this?
 
Hello again,

I found a solution to what i needed using the following procedures:

I stored current value of StudentID in public
variable lngStudentID.
-----------------------------------------------
Private Sub cboStudent_GotFocus()
If Not IsNull(Me.cboStudent.Value) Then
lngStudentID = Me.cboStudent.Value
End If
End Sub


I used DLookup to check for existing record.
--------------------------------------------------
Private Sub cboStudent_AfterUpdate()
Dim intZ As Long

On Error GoTo errIsNull

intZ = DLookup("[StudentID]", "StudentProfile", "[StudentID] = " &
Me.cboStudent.Value)
MsgBox "Employee " & Me.cboStudent.Value & " is already in the database."
Me.cboStudent.Value = lngStudentID
Exit Sub

errIsNull:
MsgBox "Selected employee was not found." & Chr$(13) & "Create a new record
for this employee."
End Sub
 
not sure what you're ultimately trying to accomplish. if you want to prevent
the user from changing the value of the StudentID, why not just prevent the
control bound to StudentID from being edited when a value already exists in
it? can you explain in some detail what you're trying to do?

btw, in your posted code, lngEmpID is not a public variable. it is declared
within the procedure, and it will exist only until the procedure ends. so
you can't compare the variable to anything outside the confines of that
procedure.

hth
 
Tina,

I had already tried setting the controls Locked value to yes, but that
didn't allow for selecting a new value from the Combo. Thus, I did a rework
using DLookup to check for existing values and proceeded from there.

Of course, the reason for all this is when I showed the database to a user
one thing she did was switch student names to create a new record, NOT GOOD.
So, I had to figure out how to allow users to select a student name without
replacing the current student ID.

Also, you were right about lngEmpID. I changed the name and moved it to the
top of the procedure where it would be public. Anyway, thank you for your
input on this.

-AKA
 
Back
Top