Saving auto-added Date

shafara7

Registered User.
Local time
Today, 06:22
Joined
May 8, 2017
Messages
118
I have a Form A where it displays the dates of the records based on Table A.
Then I have a Pop-up Form where I enter some details of the record. There is a textbox where I can enter the date of the record.
I am attempting to save the date entered from the Pop-up Form onto the Form A.

The initial code was
Code:
If Not IsNull(txtDate.value) Then

        If cboTaskType.Column(2) Like "Analyse*" Then 
            CurrentDb.Execute "UPDATE tblA SET datDate = #" & datConvert(txtDate.value) & "# WHERE xxx ;"

[B]        ElseIf (txtDate.value = workdaysAdd([datDateIs], getKPI("Measurement", False))) Then
            CurrentDb.Execute "UPDATE tblA SET datDate = NULL WHERE xxx;"
[/B]
        Else
            CurrentDb.Execute "UPDATE tblA SET datDate = #" & datConvert(txtDate.value) & "# WHERE xxx ;"
        End If

    End If

With the above code, Form A will show the date value that is entered on the Pop-up Form. Which is okay.
But when there is no value entered at the Pop-up Form, the Form A date also shows nothing.
I know, because I have set it to NULL when there is no value entered.

For your info, "txtDate.value = workdaysAdd([datDateIs], getKPI("Measurement", False))" means that when no date is entered, it will show a previous date which has been added by 4.
Which means when the previous date was 01.07.2017, it will show 05.07.2017.
That code works fine because I am using it on other forms.

The problem is, how do I show this added date into Form A?

I have tried editing the codes as shown below but it's not working.

Code:
If Not IsNull(txtDate.value) Then
[B]Dim datDateAuto As Date
datDateAuto = workdaysAdd([daDatetIs], getKPI("Measurement", False))[/B]

        If cboTaskType.Column(2) Like "Analyse*" Then 
            CurrentDb.Execute "UPDATE tblA SET datDate = #" & datConvert(txtDate.value) & "# WHERE xxx ;"

        ElseIf (txtDate.value = workdaysAdd([datDateIs], getKPI("Measurement", False))) Then
            CurrentDb.Execute "UPDATE tblA SET datDate = [B]#" & datMessungAuto & "#[/B] WHERE xxx;"

        Else
            CurrentDb.Execute "UPDATE tblA SET datDate = #" & datConvert(txtDate.value) & "# WHERE xxx ;"
        End If

    End If
 
You could use a Public variable to pass information between different forms. You're close with your 2nd example.

In a module, at the top, enter:
Code:
Public datDateAuto as Date
then in Form B use:
Code:
datDateAuto = workdays.....
(like you are), and in Form A (or anywhere else) you can retrieve the value of datDateAuto .

Here's some info from MSDN on declaring variables Dim, Private, Public, etc.

public_Variables.jpg

dbeMZa
 
Last edited:

Users who are viewing this thread

Back
Top Bottom