Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current date to bound date filed 1

Status
Not open for further replies.

anujkmehrotra

Programmer
Jan 21, 2012
17
0
0
I'm getting an error in the following line:
Me.LicLogDt = Date
I want to update LicLogDt(bound date field) to get current date of system on form load/open, but error says "Can't assign a value". It is working on Form Close but not on Open/Load. Please guide to do so.
----------
Code:
----------
Private Sub Form_Load()
If Date < Me.LicLogDt Then
MsgBox ("System date is less than last login date. Please set your system date to current first and login again."), vbInformation, "Error"
DoCmd.Close
Else
Me.LicLogDt = Date
If Me.LicLogDt >= Me.LicExpDt Then
MsgBox ("Trail period has been expired. Please purchase full version of Auto Evolution today."), vbCritical, "Demo Expired"
CurrentDb.Execute "UPDATE tblLicence SET strCheckLicence = 'Validation' WHERE idLicence = 1"
End If
End If
End Sub
---------

Thanks & Regards,
Anuj
 
If it works for latter events may be a timing issue.
What happens if you move it to the
Current event
Reason is the order is
Open → Load → Resize → Activate → Current
Also place doevents before calling that line of code. There may be pending issues.

Is the initial query editable. In other words do you change the recordsource before the close event.
 
Thanks for your reply, but i'm little weak in VBA. can you reply exactly what should i do? because I tried your suggestion, it didn't work at all.

Thanks & Regards,
Anuj
 
I am guessing because this may not be the cause. But I would try changing the event from load to current.

Private Sub Form_Current()
your code
....
doevents
Me.LicLogDt = Date
....
you code
end sub
 
the forms data should be available with the Load event. On Open the data hasn't loaded yet. You may try to assign the value of the text with vba which is really how it should be done .. away from the users sight

How about something like this? You will need to change the table and field names to reflect yours

Code:
Private Sub Form_Load()

    Dim db As DAO.Database
    Dim rs As DAO.Recordset

    Set db = CurrentDb()
    Set rs = db.OpenRecordset("MyDateTable")

    If Date < rs!LicLogDt Then
        MsgBox ("System date is less than last login date. Please set your system date to current first and login again."), vbInformation, "Error"
        DoCmd.Close
    Else
        With rs
            .Edit
            .Fields("LicLogDt") = Date
            .Update
        End With
        If Date >= rs!LicExpDt Then
            MsgBox ("Trail period has been expired. Please purchase full version of Auto Evolution today."), vbCritical, "Demo Expired"
            CurrentDb.Execute "UPDATE tblLicence SET strCheckLicence = 'Validation' WHERE idLicence = 1"
        End If
    End If
End Sub

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
Thanks MazeWorX,

it worked well and I will keep your logic and suggestion in my mind.

Thanks & Regards,
Anuj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top