How to open a form based on data entered into INPUTBOX, unless there are more than one matching records

Hello Experts,
I have records with the following type of Primary Key...   YYYY-MM-11111.  
(Year record was created, month created, sequential 5 digit # counting from the 1st of each year)  
Relatively new database, currently they are up to "2015-02-00841"  

I'd like to tie some code to a command button that asks for the last 5 digits, and opens a form with the matching record.   The challenge comes in that if there are more than one records that have those last 5 digits, it would need to bring up a list of the matching records... the user could then select a record from that list to open the form.

The above is the basic need....
What would be awesome is that if it did find more than one record that matched the last 5 digits BUT all but one were more than XX days old, it would not present the list, but go ahead and open the form with the most recent record.

Any help would be appreciated.
TechGuiseAsked:
Who is Participating?
 
Rey Obrero (Capricorn1)Commented:
try this as you requested

 Private Sub Command0_Click()
 Dim strFind As String, strPrefix As String, strNum As String
 strPrefix = Year(Now())
 strNum = InputBox("Enter: Number 00000")

 If strNum & "" <> "" Then
     strFind = strPrefix & "-**-" & strNum
     Debug.Print strFind
     DoCmd.OpenForm "Form1", , , "[PKName] Like '" & strFind & "'"
 End If
 End Sub
0
 
PatHartmanCommented:
A simple way is to use a combo.  Create a query that selects the ID's as field 1 and then the last 5 digits as field 2 suffixed by the YYYY-MM instead of prefixed by it.  Order the query by field 2.  Use this query as the rowsource for the combo.  Hide field1, show field 2.  If you add the combo to a bound form using the wizard, one of the options will be to find a record on the current form, choose that one.
0
 
Rey Obrero (Capricorn1)Commented:
try this as you requested

Private Sub Command0_Click()
Dim strFind As String, strPrefix As String, strNum As String
strPrefix = Year(Now())
strNum = InputBox("Enter: Number 00000")
Stop
If strNum & "" <> "" Then
    strFind = strPrefix & "-**-" & strNum
    Debug.Print strFind
    DoCmd.OpenForm "Form1", , , "[PKName] Like '" & strFind & "'"
End If
End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.