K
kaosyeti
can anyone tell me why the following code causes access to crash? the
control in question is unbound, fyi. strangely, i ran through the code step-
by-step and it didn't seem to crash until after it finished executing but if
i remove the code, it won't crash. i'm not a developer so don't make fun.
Private Sub txtboxstocknumber_BeforeUpdate(Cancel As Integer)
Dim strWhere As String
Dim hldStockNum As String
Dim ctrlCurrent As Control
hldStockNum = Me.txtboxstocknumber
strWhere = "[stocknumber] = " & Chr(34) & hldStockNum & Chr(34)
If IsNull(DLookup("[stocknumber]", "tblusedcars", "[stocknumber] = " &
Chr(34) & hldStockNum _
& Chr(34))) = True Then
Cancel = True
Me.Undo
Call MsgBox("That stock number is not in the system. Please exit
to the Used Vehicle Manager to enter the vehicle or choose a different stock
number.", vbInformation, "New Vehicle")
Me.txtboxstocknumber.Undo
Else
If DCount("*", "tblusedcars", "[stocknumber] = " & Chr(34) &
hldStockNum _
& Chr(34)) > 1 Then
Call MsgBox("More than one vehicle record has been found with
this stock number. Please use the record navigation buttons at the bottom of
the screen to select the appropriate vehicle before making any changes.",
vbInformation, "Duplicate Stock Numbers")
Cancel = True
Me.Undo
Me.txtboxstocknumber.Undo
Me.Filter = strWhere
Me.FilterOn = True
Me.chkboxauction = -1
For Each ctrlCurrent In Me.Controls
If ctrlCurrent.Tag = "filtered" Then
ctrlCurrent.Visible = True
End If
Next ctrlCurrent
Else
Cancel = True
Me.Undo
Me.txtboxstocknumber.Undo
Me.Filter = strWhere
Me.FilterOn = True
Me.chkboxauction = -1
For Each ctrlCurrent In Me.Controls
If ctrlCurrent.Tag = "filtered" Then
ctrlCurrent.Visible = True
End If
Next ctrlCurrent
End If
End If
End Sub
control in question is unbound, fyi. strangely, i ran through the code step-
by-step and it didn't seem to crash until after it finished executing but if
i remove the code, it won't crash. i'm not a developer so don't make fun.
Private Sub txtboxstocknumber_BeforeUpdate(Cancel As Integer)
Dim strWhere As String
Dim hldStockNum As String
Dim ctrlCurrent As Control
hldStockNum = Me.txtboxstocknumber
strWhere = "[stocknumber] = " & Chr(34) & hldStockNum & Chr(34)
If IsNull(DLookup("[stocknumber]", "tblusedcars", "[stocknumber] = " &
Chr(34) & hldStockNum _
& Chr(34))) = True Then
Cancel = True
Me.Undo
Call MsgBox("That stock number is not in the system. Please exit
to the Used Vehicle Manager to enter the vehicle or choose a different stock
number.", vbInformation, "New Vehicle")
Me.txtboxstocknumber.Undo
Else
If DCount("*", "tblusedcars", "[stocknumber] = " & Chr(34) &
hldStockNum _
& Chr(34)) > 1 Then
Call MsgBox("More than one vehicle record has been found with
this stock number. Please use the record navigation buttons at the bottom of
the screen to select the appropriate vehicle before making any changes.",
vbInformation, "Duplicate Stock Numbers")
Cancel = True
Me.Undo
Me.txtboxstocknumber.Undo
Me.Filter = strWhere
Me.FilterOn = True
Me.chkboxauction = -1
For Each ctrlCurrent In Me.Controls
If ctrlCurrent.Tag = "filtered" Then
ctrlCurrent.Visible = True
End If
Next ctrlCurrent
Else
Cancel = True
Me.Undo
Me.txtboxstocknumber.Undo
Me.Filter = strWhere
Me.FilterOn = True
Me.chkboxauction = -1
For Each ctrlCurrent In Me.Controls
If ctrlCurrent.Tag = "filtered" Then
ctrlCurrent.Visible = True
End If
Next ctrlCurrent
End If
End If
End Sub