Accesste ana diye bir tablom var. Bu tablo içerisinde “Nakil Gitti” alanı var. Bir de…
- User
Accesste ana diye bir tablom var. Bu tablo içerisinde “Nakil Gitti” alanı var. Bir de “Nakil Gitme Tarihi” Alanı var. Ben nakil gittiyi evet olarak işaretlediğimde işaretlendiğim tarihi nakil gitme tarihi olarak otomatik kaydedilmesini istiyorum.
- Assistant
Microsoft Access allows you to automate tasks like the one you described using event procedures in forms. When you mark the "Nakil Gitti" field as "Yes", you can automatically set the "Nakil Gitme Tarihi" (Transfer Leaving Date) field to the current date. Here's how you can achieve this:
Steps to Automatically Set "Nakil Gitme Tarihi" When "Nakil Gitti" Is Marked as Yes:
-
Ensure You Have a Form for Data Entry:
- First, make sure you're using a form to input data into your "ana" table. Forms allow you to run VBA code upon events like updating a field.
-
Open the Form in Design View:
- In the Navigation Pane, right-click your form and select Design View.
-
Select the "Nakil Gitti" Control:
- Click on the control (checkbox or dropdown) that's bound to the "Nakil Gitti" field.
-
Access the Property Sheet:
- If the Property Sheet isn't visible, press F4 or go to the Design tab and click on Property Sheet.
-
Navigate to the Events Tab:
- In the Property Sheet, click on the Events tab to see the list of events associated with the control.
-
Find the "After Update" Event:
- Look for the After Update event in the list. This event occurs after the control's data is updated.
-
Create an Event Procedure:
- Click on the empty field next to After Update, then click the [...] button that appears. Choose Code Builder to open the VBA editor.
-
Write the VBA Code:
-
In the VBA editor, you should see a subroutine that looks like this:
Private Sub Nakil_Gitti_AfterUpdate() End Sub -
Inside this subroutine, add the following code:
If Me.[Nakil Gitti] = True Then Me.[Nakil Gitme Tarihi] = Date() Else Me.[Nakil Gitme Tarihi] = Null ' Optional: Clear the date if unchecked End If -
Explanation:
Me.[Nakil Gitti]refers to the current value of the "Nakil Gitti" field on the form.Date()returns the current date.- The code checks if "Nakil Gitti" is True (Yes). If so, it sets "Nakil Gitme Tarihi" to today's date.
- If "Nakil Gitti" is False (No), it sets "Nakil Gitme Tarihi" to Null (clears the date). This line is optional; remove it if you prefer to retain the date even when "Nakil Gitti" is unchecked.
-
-
Save and Close the VBA Editor:
- Click File > Save (or simply close the VBA window and save when prompted).
-
Test the Form:
- Switch the form to Form View.
- Check the "Nakil Gitti" box and see if the "Nakil Gitme Tarihi" field automatically fills with the current date.
- Uncheck the "Nakil Gitti" box and see if the date field clears (if you included the line to set it to Null).
Tips:
-
Field Names with Spaces:
- Since your field names contain spaces, ensure you wrap them in square brackets
[]in your VBA code to avoid syntax errors. - Example:
Me.[Nakil Gitme Tarihi]
- Since your field names contain spaces, ensure you wrap them in square brackets
-
Prevent Overwriting Existing Dates:
-
If you want to prevent the date from changing once it's set (even if "Nakil Gitti" is toggled again), you can modify your code:
If Me.[Nakil Gitti] = True And IsNull(Me.[Nakil Gitme Tarihi]) Then Me.[Nakil Gitme Tarihi] = Date() End If -
This code sets the date only if "Nakil Gitti" is checked and "Nakil Gitme Tarihi" is currently empty.
-
-
Future Changes in "Nakil Gitti":
- Decide how you want the date field to behave if "Nakil Gitti" is unchecked after being checked:
- Retain the Date: Don't include the line that sets the date field to Null.
- Clear the Date: Keep the line
Me.[Nakil Gitme Tarihi] = Null.
- Decide how you want the date field to behave if "Nakil Gitti" is unchecked after being checked:
Conclusion:
By following these steps, you can automate the process of recording the date when "Nakil Gitti" is marked as "Yes". This approach ensures data accuracy and saves time by eliminating the need to manually enter the date. Remember to test thoroughly to ensure it behaves as expected in all scenarios.
If you have any questions or need further assistance, feel free to ask!
-