text box search, open new form.


/ Published in: VB.NET
Save to your folder(s)

I have a default value of "Edit me!" in my search box on switchboard form. Code below clears out that edit me on focus, and then clicking button obviously will search for and open up a form to the record, throwing a MsgBox error if not found.


Copy this code and paste it in your HTML
  1. 'When clicking on text box, clear out the "Edit me!"
  2. Private Sub txtSearch_GotFocus()
  3. txtSearch.Value = ""
  4. End Sub
  5. Private Sub btnSearch_Click()
  6. On Error GoTo Err_btnSearch_Click
  7.  
  8. Dim stDocName As String
  9. Dim stLinkCriteria As String
  10.  
  11. stDocName = "frmSearch"
  12. stLinkCriteria = "[Barcode]=" & Me![txtSearch]
  13.  
  14.  
  15. 'Experts Exchange for DCount example!
  16. 'http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_23339231.html?sfQueryTermInfo=1+access+null+stlinkcriteria
  17.  
  18. If DCount("*", "tblInventoryInformation", stLinkCriteria) = 0 Then
  19. MsgBox ("Oops! Barcode not found!")
  20. txtSearch.Value = ""
  21. Else
  22. DoCmd.OpenForm stDocName, , , stLinkCriteria
  23. End If
  24.  
  25.  
  26. Exit_btnSearch_Click:
  27. Exit Sub
  28.  
  29. Err_btnSearch_Click:
  30. MsgBox Err.Description
  31. Resume Exit_btnSearch_Click
  32.  
  33. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.