Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Search Button on My Order Entry Form
Neal Austin 
      
4 months ago
HI, i have done many search buttons on my order entry form to bring up all orders from a specific customer based on customer name. What i also want to do, is to have a search button, on my order entry form, that will bring up an input box, then i can enter in the customer id for a specific customer, then it will filter and show all orders that i have for that customer, again based on the customer id, not the customer name.

thanks
Alex Lewis  @Reply  
       
4 months ago
DetailsPrivate Sub SearchBtn_Click()

Dim S as String

S = InputBox([Enter prompt for CustomerID here])

If S = [Enter CustomerID here] Then Me.RecordSource = "SELECT * FROM OrderT WHERE CustomerID=" & CLng(S)

End If

End Sub
Sandra Truax  @Reply  
         
4 months ago
Try this:

DetailsPrivate Sub SearchBtn_Click()

    Dim S As Variant
    
    S = InputBox("Enter CustomerID")
    
    ' User clicked Cancel
    If S = "" Then Exit Sub
    
    ' Make sure it is numeric
    If Not IsNumeric(S) Then
        MsgBox "Please enter a valid numeric CustomerID.", vbExclamation
        Exit Sub
    End If
    
    Me.RecordSource = _
        "SELECT * FROM OrderT WHERE CustomerID = " & CLng(S)

End Sub
Kevin Robertson  @Reply  
          
4 months ago
Neal Here is another example:

    Dim S As String, ID As Long
    
    S = InputBox("Enter Customer ID", "Customer ID")
    
    If S = "" Then Exit Sub
    If Not IsNumeric(S) Then Exit Sub
    If InStr(S, ".") <> 0 Then Exit Sub
    
    ID = CLng(S)
    If ID < 0 Then ID = ID * -1
    
    DoCmd.OpenForm "OrderListF", , , "CustomerID=" & ID


This example opens a Continuous Form and displays the relevant records and also includes some validation checks.
Neal Austin OP  @Reply  
      
4 months ago
Kevin, your code does not make the entered ID # go to that record.

Here is my code for searching and filtering a customers order records based on Name. I want the same thing but with customer ID that is assigned with autofill.

thanks -

Dim S As String, LN As String
        
        S = InputBox("Please enter First Name Or Last Name", "Customer Search")
        If S = "" Then Exit Sub
        
        LN = Nz(DLookup("CustomerName", "CustomerT", "CustomerName LIKE ""*" & S & "*"""), "")
        If LN = "" Then
            
            DoCmd.GoToRecord acDataForm, "OrderEntryF", acNewRec
            DoCmd.GoToControl "FirstName"
            
            Exit Sub
        End If
        
        Me.Filter = "CustomerName LIKE ""*" & S & "*"""
        Me.FilterOn = True

Neal Austin OP  @Reply  
      
4 months ago
ok i got the code to work with some error handling. what i need now is to add a section, maybe dcount, to this current code, so if i enter a customer id in, and it is a real customer, ( this part already done), but has no orders, will pop up a msg saying no orders. right now if i enter in a customer id that has no orders, it just ends the sub.

here is my current code:

Dim ID As String, LN As String
      
    
        ID = InputBox("Please enter Customers's ID #", "Customer's ID # Search", "")
        
        If ID = "" Then
            MsgBox "There is no Customer assigned to that ID #", vbOKCancel, "No Customer Found!"
        
        ElseIf Not IsNumeric(ID) Then
            MsgBox "There is no Customer assigned to that ID #", vbOKCancel, "No Customer Found!"
        
        Else
                
        LN = Nz(DLookup("CustomerID", "CustomerT", "CustomerID=" & ID), 0)
        If LN = 0 Then
            MsgBox "There is no Customer assigned to that ID #", vbOKCancel, "No Customer Found!"
                      
            Exit Sub
        End If
        
        Me.Filter = "CustomerID=" & ID
        Me.FilterOn = True
        End If
Kevin Robertson  @Reply  
          
4 months ago
You have the same message in 3 places. I would add a sub routine for the message, then call that sub when you need to display the message. This way if you decide you want to change the message you only need to change it in one place.
Neal Austin OP  @Reply  
      
4 months ago
ok, i can work on that, but i still need to address the issue, if i enter in a customer id that is currently being used, it wont show any orders on my order entry page, because that customer has none yet. I need to add some code that goes and looks to see if there are any orders created for that customer, and if not have it return a msg that states customer has no orders. As of right now, all it does it ends the sub..
Kevin Robertson  @Reply  
          
4 months ago
Just perform another DLookup.

oID = Nz(DLookup("OrderID", "OrderT", "CustomerID=" & ID), 0)

if a 0 is returned there are no orders.
Neal Austin OP  @Reply  
      
4 months ago
ok, any hint on where in my code that should go? i have tried several spots, but it just messes up the results.  thanks
Neal Austin OP  @Reply  
      
4 months ago
actually i figured out that if i add the following code below the filter code, then it does what i want it to.
If Me.Recordset.RecordCount = 0 Then
            MsgBox "Sorry, this customer does not have any orders yet!", , "No Orders Yet!"
        End If

thanks for your help, it helped guide me to the things to try..

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/11/2026 3:30:48 AM. PLT: 1s