Answer :
Final answer:
To create a new query in MS Access using a custom function, follow these steps:
- Create a new module named 'CustomFunctions'.
- In the CustomFunctions module, define the custom function named 'Travel'.
- Create a new query in Query Design View and add the desired fields from the Consultant table.
- Add a calculated field named 'TravelExpense' using the custom function 'Travel' with the appropriate arguments.
- Save the query as 'TravelCalculation' and test it in Datasheet View.
Explanation:
To create a new query in MS Access using a custom function, follow these steps:
Step 1: Create a new module
Open MS Access and go to the Database Tools tab. Click on the Visual Basic button to open the Visual Basic for Applications (VBA) editor. In the VBA editor, go to Insert and click on Module to create a new module. Name the module 'CustomFunctions'.
Step 2: Define the custom function
In the CustomFunctions module, enter the following code:
Function Travel(CountryValue, SalaryValue)
If CountryValue = ""USA"" Then
If SalaryValue < 60000 Then
Travel = 2000
ElseIf SalaryValue < 70000 Then
Travel = 1500
End If
End If
End Function
Step 3: Create a new query
Go to the Create tab and click on Query Design. Select the Consultant table and add the LastName, Reside, and Salary fields to the query design grid.
Step 4: Add the calculated field
In the query design grid, right-click on an empty column and select Build... from the context menu. In the Expression Builder, enter the following expression:
Travel([Reside], [Salary])
Name the calculated field 'TravelExpense'.
Step 5: Save and test the query
Save the query with the name 'TravelCalculation'. Switch to Datasheet View to test the new custom function and calculated field. Close the TravelCalculation query when done.
Learn more about creating a new query in ms access using a function here:
https://brainly.com/question/31230588
#SPJ14