ComboBox Filter Question

hascons

Registered User.
Local time
Today, 15:11
Joined
Apr 20, 2009
Messages
58
Hello,

I have a form that uses a combobox filter. it works for all the records except the first record. When I select the first record I get an error message..(Either BOF or EOF is True. I would assume that it would be true as the record selected is the very First One. I have played around with a few BOF if statements but can't seem to fix this problem.

The code below is from another idea that if I moved right to the first record in a recordset that I could then check to see if the ID Value matched that of the ComboBox. This doesn't work either.

Can anyone see anything obvious with this Procedure?

rstSuppliers is an ADO Recordset that is declared at the decleration section of this forms Module. It is Opened on the Sub Open event.

Private Sub cboSupplier_Click()
Dim intReturn As Integer
Dim strCriteria As String
Dim FullName As String

strCriteria = "SuppliersID = " & "'" & Me.cboSupplier & "'"

rstSuppliers.MoveFirst

If rstSuppliers!SuppliersID <> "'" & Me.cboSupplier & "'" Then

Me.cmdSave.Enabled = False
rstSuppliers.MoveFirst
rstSuppliers.Find strCriteria, 1, adSearchForward

End If

FullName = rstSuppliers!SuppliersName

intReturn = UnBoundDisplay(Me, rstSuppliers, FullName)


' Clear ComboBox
Me.cboSupplier = ""
End Sub
 
Me thinks that you are using the wrong event. Try AfterUpdate instead.
When using the On Click event the value of the combobox can still be NULL(or the previous value). You want the procedure to run after the choice was made and not when you are just clicking the combobox.

Enjoy!
 
Thanks Guus2005 for your response,

However I had tried that after I posted here, I did figure the AfterUpdate wpould be more appropiate. This however did not solve the problem. I 've added a BOF check before running the search but this also does not seem to solve the problem.

I've reposted the updated code. Any Suggestions?

Private Sub cboSupplier_AfterUpdate()
Dim intReturn As Integer
Dim strCriteria As String
Dim FullName As String

If Not rstSuppliers.BOF Then

strCriteria = "SuppliersID = " & "'" & Me.cboSupplier & "'"

Me.cmdSave.Enabled = False
rstSuppliers.MoveFirst
rstSuppliers.Find strCriteria, 1, adSearchForward


FullName = rstSuppliers!SuppliersName

intReturn = UnBoundDisplay(Me, rstSuppliers, FullName)

End If

' Clear ComboBox
Me.cboSupplier = ""
End Sub
 
Hello,

Just Wanted To give an update. I did figure this out.

The Line:

rstSuppliers.Find strCriteria, 1, adSearchForward Should have Been:

rstSuppliers.Find strCriteria, 0, adSearchForward

The 1 was causing the record to skip the first record.
 

Users who are viewing this thread

Back
Top Bottom