I am using following code and want to go to the record where condition ID=[Screen][Active Control] through a ComboBox
Private Sub CBO_STD_ID_AfterUpdate()
If IsNull([Screen].ActiveControl) Then
DoCmd.GoToControl "[CBO_STD_ID]"
End If
varActContVal = [Screen].ActiveControl
DoCmd.GoToRecord , , acGoTo, Screen.ActiveControl
End Sub
Note:
Screen.ActiveControl is the value input by unbounded comboBox.
This the value of Filed ID of the table/Query rawsource of the form.
I want to go to the record where condition ID=[Screen].[ActiveControl]
The above mentioned code works well for first 39 records and then it react strangely and gives wrong results.
On investigation into table it found that ID number form 1-39 are without break, then records having ID 40, 41,44,67,92,97,137,146,191 are deleted from table.
Problem came onward from record having ID more then 39. Results are as under:
on selection from 1-39 go to correct record
on Selection ID 42 it goes to ID 45 two records forward
on Selection ID 45 it goes to ID 48 three records forward
on Selection ID 66 it goes to ID 70 four records forward
on Selection ID 68 it goes to ID 72 five records forward
On Selection ID 93 it goes to ID 104 six records forward .... and so on
On selecting last 8 to 10 records a run time error message says ' You can not go to the specific record'
I am unable to understand the behavior of database in this regards. If you understand please let me know how can i fix it.
ID is the primary key of the table
and records related to ID 40, 41,44,67,92,97,137,146,191 are deleted from table.
What I understands from this behavior of comboBox record selection, it goes to record number serial from top,
and whereas the value of Screen.ActiveControl is the ID number of primary key, which is higher then the serial number of the record due to deleted records in between.
I therefore also had tried the code SearchForRecord with where condition as under
DoCmd.SearchForRecord , , acGoTo, "ID =" & Me.CBO_STD_ID
DoCmd.SearchForRecord , , acGoTo, "ID =" [Screen].[ActiveControl]
instead of
DoCmd.GoToRecord , , acGoTo, Screen.ActiveControl
But all fails, a run time error message shows.
Please help in this regards where i am doing mistake.
Thanks and regards
Haseebul Hasan