update two fields using a type-in field

aziska

New Member
Joined
Feb 15, 2012
Messages
13
Ok, I'm working on a form in access 2010. I'm attempting to have the form update two fields, (A title and a description field) when you type in the code associated with each title/description. The code field is 6 characters long. I would like it to search the "dictionary", the table that holds all of the information, when you type in a 6 digit string in the code field and if it finds a match, update the title and description fields and if no match, return "No matches found." Any help or links would be much appreciated. If you need any additional information I'll do my best to provide it.. Thank you!

Aaron
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
aziska -

You may want to try something like this...hope that helps!

Private Sub cmdSearch_Click()
ClearSearchResults
ExecuteSearch
End Sub

Private Sub Form_Load()
ClearSearchResults
End Sub

Private Sub ClearSearchResults()
With Me
.txtTitle = ""
.txtDescription = ""
.txtSearchStatus = ""
End With
End Sub

Private Sub ExecuteSearch()
Dim rst As DAO.Recordset, SQL As String

With Me
If Len(Nz(Trim(.txtSearchCriteria), "")) = 0 Then
MsgBox "A value is required in the Code field.", vbInformation
.txtSearchCriteria.SetFocus
Exit Sub
End If

SQL = "SELECT [Title], [Description] FROM [tblDictionary] WHERE
Code:
 = """ & .txtSearchCriteria & """"
        
        Set rst = Application.CurrentDb.OpenRecordset(SQL)
        
        If Not rst.EOF Then
            .txtTitle = rst.Fields("Title").Value
            .txtDescription = rst.Fields("Description").Value
        Else
            .txtSearchStatus = "No matches found."
        End If
        
        rst.Close
        Set rst = Nothing
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top