473,486 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

The search key was not found in any record ?!

374 Contributor
Well I created my first try at form validation through using the before update event. However I am now having issues.

I am validating a subform on my main form. The validation code is held within the subform. I have 2 comboboxes and 2 text areas. The validation is messing up if I fill out 1 of any of these boxes and leave the rest blank.

I get the following error:

"The search key was not found in any record."

Here is a screen shot of the state:



Weirdly if I fill in the Cost figure field with a non zero value it doesnt happen, however it doesnt validate the department cost inccurred by field:



The code I am using is as follows:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Option Compare Database
  3.  
  4.  
  5.  
  6. Private Sub costadd_Click()
  7. On Error GoTo Err_btnaddactioncorrective_Click
  8.  
  9.  
  10.     DoCmd.GoToRecord , , acNewRec
  11.  
  12. Exit_btnaddactioncorrective_Click:
  13.     Exit Sub
  14.  
  15. Err_btnaddactioncorrective_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_btnaddactioncorrective_Click
  18. End Sub
  19.  
  20. Private Sub costdelete_Click()
  21. On Error GoTo Err_btndeleteacorrective_Click
  22.  
  23.  
  24.     DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  25.     DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
  26.  
  27. Exit_btndeleteacorrective_Click:
  28.     Exit Sub
  29.  
  30. Err_btndeleteacorrective_Click:
  31.     MsgBox Err.Description
  32.     Resume Exit_btndeleteacorrective_Click
  33. End Sub
  34.  
  35. Private Sub costfirst_Click()
  36. On Error GoTo Err_btncorrectivefirst_Click
  37.  
  38.  
  39.     DoCmd.GoToRecord , , acFirst
  40.  
  41. Exit_btncorrectivefirst_Click:
  42.     Exit Sub
  43.  
  44. Err_btncorrectivefirst_Click:
  45.     MsgBox Err.Description
  46.     Resume Exit_btncorrectivefirst_Click
  47.  
  48. End Sub
  49.  
  50. Private Sub costlast_Click()
  51. On Error GoTo Err_btngotolastcorrective_Click
  52.  
  53.  
  54.     DoCmd.GoToRecord , , acLast
  55.  
  56. Exit_btngotolastcorrective_Click:
  57.     Exit Sub
  58.  
  59. Err_btngotolastcorrective_Click:
  60.     MsgBox Err.Description
  61.     Resume Exit_btngotolastcorrective_Click
  62. End Sub
  63.  
  64. Private Sub costnext_Click()
  65. On Error GoTo Err_btnnextcorrective_Click
  66.  
  67.  
  68.     DoCmd.GoToRecord , , acNext
  69.  
  70. Exit_btnnextcorrective_Click:
  71.     Exit Sub
  72.  
  73. Err_btnnextcorrective_Click:
  74.     MsgBox Err.Description
  75.     Resume Exit_btnnextcorrective_Click
  76. End Sub
  77.  
  78. Private Sub costprevious_Click()
  79. On Error GoTo Err_btnpreviouscorrective_Click
  80.  
  81.  
  82.     DoCmd.GoToRecord , , acPrevious
  83.  
  84. Exit_btnpreviouscorrective_Click:
  85.     Exit Sub
  86.  
  87. Err_btnpreviouscorrective_Click:
  88.     MsgBox Err.Description
  89.     Resume Exit_btnpreviouscorrective_Click
  90.  
  91. End Sub
  92.  
  93. Private Sub costsave_Click()
  94. On Error GoTo Err_btnsavecorrective_Click
  95.  
  96.  
  97.     DoCmd.RunCommand acCmdSaveRecord
  98.  
  99.  
  100.  
  101. Exit_btnsavecorrective_Click:
  102.     Exit Sub
  103.  
  104. Err_btnsavecorrective_Click:
  105.  
  106. 'capture the correct error number and just change it.
  107. If Err = 2501 Then 'The command save record has been cancelled
  108. MsgBox "Save cancelled.", vbInformation, "Info"
  109.  
  110. Else
  111.     MsgBox Err.Description
  112.     Resume Exit_btnsavecorrective_Click
  113. End If
  114. End Sub
  115.  
  116. Private Sub Form_AfterUpdate()
  117. On Error GoTo helpme
  118. DoCmd.GoToRecord , , acNext
  119. DoCmd.GoToRecord , , acPrevious
  120.  
  121. erm:
  122. Exit Sub
  123.  
  124. helpme:
  125. MsgBox Err.Description
  126. Resume erm
  127. End Sub
  128.  
  129. Private Sub Form_BeforeUpdate(Cancel As Integer)
  130. Dim ErrorStrings As String
  131.  
  132.  
  133.  
  134. 'The error string can be set to null for this first run
  135. ErrorStrings = vbNullString
  136.  
  137.  
  138. 'If the user tries to move off the record or any other event fires a save lets ask whether they actually want to do something with the changes or discard them
  139. If MsgBox("Changes have been made to this record." _
  140.         & vbCrLf & vbCrLf & "Do you want to save these changes?" _
  141.         , vbYesNo, "Changes Made...") = vbYes Then
  142.  
  143. 'Carry out the form validation to ensure everything is filled in correctly if it isnt lets get this stuff fixed and not save the current record
  144.  
  145.  
  146.  
  147.             If Len(Nz(Me.Costtype)) < 1 Then
  148.                 Me.Costtype.SetFocus
  149.                 Me.Costtype.BackColor = vbRed
  150.  
  151.                 ErrorStrings = ErrorStrings & "You must select the type of cost." & vbCrLf
  152.  
  153.             Else
  154.  
  155.                 Me.Costtype.BackColor = 16579561
  156.  
  157.             End If
  158.  
  159.             If Len(Me.CostDept) < 1 Then
  160.                 Me.CostDept.SetFocus
  161.                 Me.CostDept.BackColor = vbRed
  162.  
  163.                 ErrorStrings = ErrorStrings & "You must select the department that inccurred the cost." & vbCrLf
  164.  
  165.             Else
  166.  
  167.                 Me.CostDept.BackColor = 16579561
  168.  
  169.             End If
  170.  
  171.             If Len(Nz(Me.CostDesc)) < 5 Then
  172.                 Me.CostDesc.SetFocus
  173.                 Me.CostDesc.BackColor = vbRed
  174.  
  175.                 ErrorStrings = ErrorStrings & "You must enter an adequate cost description." & vbCrLf
  176.  
  177.             Else
  178.  
  179.                 Me.CostDesc.BackColor = 16579561
  180.  
  181.             End If
  182.  
  183.             If Len(Nz(Me.CostFig)) < 1 Or (Me.CostFig) < 1 Then
  184.                 Me.CostFig.SetFocus
  185.                 Me.CostFig.BackColor = vbRed
  186.  
  187.                 ErrorStrings = ErrorStrings & "You must enter a cost figure." & vbCrLf
  188.  
  189.             Else
  190.  
  191.                 Me.CostFig.BackColor = 16579561
  192.  
  193.             End If
  194.  
  195.  
  196.  
  197.  
  198. 'Create the if statement to see if anything has been done incorrectly before allowing continuation
  199.  
  200.             If Len(Nz(ErrorStrings)) > 0 Then
  201. 'error has occured cancel any save of the record
  202.                 MsgBox ErrorStrings, vbInformation, "Errors in your entries"
  203.                 Cancel = True
  204.                 Exit Sub
  205.             Else
  206. 'everything looks to be ok allow the code to continue running
  207.                 MsgBox "Cost record saved.", vbInformation, "Success"
  208.  
  209.             End If
  210.  
  211. Else
  212.             DoCmd.RunCommand acCmdUndo
  213.             'Clear out any of the vbred backgrounds if an undo is selected
  214.             'Me.CorrectiveDate.BackColor = 16579561
  215. Me.CostFig.BackColor = 16579561
  216. Me.CostDesc.BackColor = 16579561
  217. Me.Costtype.BackColor = 16579561
  218. Me.CostDept.BackColor = 16579561
  219.  
  220. End If
  221. End Sub
  222.  
  223. Private Sub Form_Current()
  224. Dim rst As DAO.Recordset
  225. Dim lngCount As Long
  226.  
  227. Set rst = Me.RecordsetClone
  228.  
  229. With rst
  230. If .RecordCount > 0 Then
  231. .MoveLast
  232. .MoveFirst
  233. End If
  234.  
  235. If Me.CurrentRecord > .RecordCount Then
  236.  
  237. Me.txtCostRecNo = "New Cost Record"
  238.  
  239. Else
  240.  
  241. 'Now output the results and capture new recorded added event so we do not have 3 of 2 situation.
  242.  
  243. Me.txtCostRecNo = "Cost record: " & Me.CurrentRecord & " of " & .RecordCount
  244.  
  245. End If
  246. End With
  247. End Sub
  248.  
I have this code on a couple of other subforms (modified to fit the form) and I get the same error now occuring with those.

If I open the subform ONLY everything works perfectly fine, it is only happening when I am using the subforms on a main form and validating.

Any help is appreciated!
Aug 13 '10 #1
2 3487
munkee
374 Contributor
Ok I have got the validation part working ok however this error still keeps occuring at the end of the procedure. If I step through the code the error crops up within the save button on click event within the generic error handler after running through all of the before update event.

I guess I could find the error code and supress this but I want to make sure there is nothing fundamentally going wrong here?

I have read a lot of similar posts where people have suggested it is a sign of database corruption but I really do not think this is the case here. Like I said it now runs as intended but this error just pops up at the end.
Aug 13 '10 #2
munkee
374 Contributor
More information to add:

If I fill I select options for both of the combo boxes i.e. department cost incurred by and cost type. I do not get any errors.

If I delete the selected value from the combo boxes and click save (to validate the form again). I do not get any errors.

So this only occurs on a record where no combo selection has been made.

Using debug.print

When there is a save without a selection made in the combo boxes the values of the combo boxes are both 0's

If I then make a selection in the for example the cost department the value changes to the correct ID number such as 2.

If I delete the selected value (department name) from the combo box and then resave the form validation spews out "Null" in the debug.print.
Aug 14 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1920
by: Quarco | last post by:
Hi, I am using the 'binary flag' principle for defining (multiple) modes for an element.. Elements table: id name flags 1 a 9 2 b ...
1
2090
by: A.J.M. van Rijthoven | last post by:
I have a table instrumenten (INSID Instrumentname, CATID), a table Categorie (CATID, Categorydescription), Netten (NETID, description of net) and a table (kpltblinstrument) that links the...
8
12062
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
3
15334
by: Typehigh | last post by:
I am a good programmer, but this one stumps me! I have a form with a continuous subform. The continuous subform contains records of data and may reach a depth of 1000's of entities. I have...
1
945
by: sunnysrivastava84 | last post by:
how can i search arecord using stored procedures .plz give me the code
6
1761
by: JHNielson | last post by:
This is a very simple question.... I have a form that looks up Records for an unbound drop-down list. It has worked just fine up until last night. Now the button on the form to delete a record...
4
2567
by: kathnicole | last post by:
Hi All, I would like to retreive all the records that starts, where the field CompanyName in table tblJob start with "sap*"... i assume this can be acheived by using LIKE function in query design...
2
1493
by: sukhhvinder | last post by:
Hi, I am using vb 2005 express edition. So how can i serach for particular record in MS Access through vb.net Thanks Sukhvinder
2
1005
by: grey15 | last post by:
hi...i have an application which stores records in a text file. the application loads the records in array of objects when the page is loaded. then, we can add, search, delete the records in array...
1
2721
by: David | last post by:
Hi, I have a table called 'jobserial' This contains amongst others, 2 fields called 'PSL_F_Serial' & 'PSL_L_Serial' Both of these are 'Text' fields (VarChar) which at present hold serial...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.