Need some VBA code help

  • I freely admit that my Access VBA Fu is weak, fortunately my T-SQL and Admin Fu is mighty. I have a parameter table in SQL Server that contains one record with two fields: StartDate and EndDate. My Access form allows people to change those, then when they run a report it opens a linked view that, on the SQL Server side, uses those dates to do all the work on the SQL Server before returning the result set.

    The problem is my weak Kung Fu. I'm wanting to trap a change event so that when either field is changed, it will save the record. So if someone enters StartDate 3/3/08 End Date 3/10/08 and runs a report, then changes the EndDate to 3/31/08, it'll save when the field exits because of clicking a button.

    My pitiful attempt is to trap the LostFocus event and do a dbo_Permits_DateRange.Update, and that seems to work (the record is updated), but it generates a run time error message 424, Object Required. I think the message wants the table explicitly open in code rather than the table being the data source on the form.

    So I'm not really sure where to go from here. Suggestions greatly appreciated!

    -----
    [font="Arial"]Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson[/font]

  • Use the AfterUpdate or Change event. LostFocus would fire even if you did not change anything.

    - Tim Ford, SQL Server MVPhttp://www.sqlcruise.comhttp://www.thesqlagentman.com http://www.linkedin.com/in/timothyford

  • I ended up, in the interest of time expediency, just putting a Save button on the form. One of these days I may spend some more time studying Access, I'll probably have the time after I retire. 😀

    Thanks for the suggestion, though.

    -----
    [font="Arial"]Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson[/font]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply