![]() |
|
|||||||
![]() |
|
Microsoft Access - Macro to do record lookups???
|
![]() |
LinkBack | Thread Tools | ![]() |
Display Modes | ![]() |
|
|||
|
I want to have a text box in a form that asks what application # the user would like to view. After they type in what application they want to edit, there will be a command box underneath that when clicked will run a macro. So if they select application # 12, it would take them to the form for the data entry for application #12 so they can edit some info. I would have used the record selector button at the bottom of the forms, but application #12, isn't necessarily record 12 in the form if you know what I mean. Is there some kind of macro I can set up to run with conditional formatting? I only have 20 applications and that is all there will be, so I was hopgin I could run a macro that has the condition something along the line of "If ApplicationNumber = 12 then GoTo Record 14 of frmApplicationEntry" (I know that code is way off, but I was trying to get my point across)
|
| Links |
|
|
|
|||
|
If I understand you correctly, this is what you need to happen: Regardless of the application number the user enters, they will go to the same form (frmApplicationEntry). The application number they enter determines what record they need to go to (ApplicationNumber = 12 then go to Record 14). If so, this is a simple fix (although not the "best practice"...but let's not go there). Create a new table. Call it Translation. In this table, create two columns. One column is called RecordNumber. One column is called ApplicatonNumber. Set the data type for both columns to Number.
Go to the form where the user enters their Application number. Instead of the user typing in whatever they want in a text box, create a combo box where the Row Source is the Translation table. (I assume you know how to do this.) Call the combo box cboApplicationNumber. IMPORTANT:Make sure that both the RecordNumber and the ApplicationNumber are included in the Row Source! And make sure that the ApplicationNumber is the first column and the RecordNumber is in the second column! Now in the Properties of the combo box, set the Column widths to 0";1". Doing this will allow the user only see the second column from the Translation table (the Application Number) but the form is really going to use what is "hidden" in the first column (because we set it's width to 0") which is the RecordNumber. Having the combo box is also nice because if you set the Property "Limit to List" to Yes forces the user to only enter what choices you give them - literally limit them to the list. That helps cut down on user error and confusion. Now instead of using a macro, put code on your command button to open the frmApplicationEntry. I assume you know how to use the wizard for creating a command button that will open a form. If not, try it. Super easy. On the 3rd screen of the wizard, select the option "Open the form and find specific data to display". On the 4th screen you will set the cboApplicationNumber equal to the frmApplicationEntry RecordNumber. Finish the wizard and name your command button cmdOpen. Your code should look like this. Private Sub cmdOpen_Click() On Error GoTo Err_cmdOpen_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "frmApplicationEntry" stLinkCriteria = "[RecordNumber]=" & Me![cboApplicationNumber] DoCmd.OpenForm stDocName, , , stLinkCriteria Exit_cmdOpen_Click: Exit Sub Err_cmdOpen_Click: MsgBox Err.Description Resume Exit_cmdOpen_Click |
![]() |
| Thread Tools | |
| Display Modes | |
|
|