macros - How to setup a scheduled task in Windows XP to run a Marcro in ms-access? -


i typically have need run process each day prior arrival @ office. set scheduled task.

how can accomplished?

is there best practice on doing this?

can or should done programmatically?

to resolve did following:

  • created macro named "submit".

  • created scheduled task .job file going to:

    start > programs > accessories > system tools > schedule tasks

scheduled task dialog box

(this produced .job file in following location: "c:\windows\tasks\submit.job")

once created, placed following syntax run: text box.

"c:\program files\microsoft office\office11\msaccess.exe"  "c:\mydatabasepath\mydatabasename.mdb" /x "submit" 

after this, remaining portion of setup completed normal schedule task should be. can find more details how manually setup these tasks here or if perform setup through command line, this particularly useful reference.

note: both macro , job file must setup work correctly.

as best practices, found this site include great deal of useful information , when , how tool should used, complements of microsoft.

one way accomplish programmatically utilize job api's. here 1 such example accomplished using vba:

see reference here

option explicit ' schedule api's declare function netschedulejobadd lib "netapi32.dll" _ (byval servername string, buffer any, jobid long) long  ' schedule structure type at_info     jobtime     long     daysofmonth long     daysofweek  byte     flags       byte     dummy       integer     command     string end type  ' schedule constants const job_run_periodically = &h1 const job_noninteractive = &h10 const nerr_success = 0  private sub command1_click()     dim lngwin32apiresultcode long     dim strcomputername string     dim lngjobid long     dim udtatinfo at_info      ' convert computer name unicode     strcomputername = strconv(text1.text, vbunicode)      ' setup tasks parameters     setstructvalue udtatinfo      ' schedule task     lngwin32apiresultcode = netschedulejobadd(strcomputername, udtatinfo, lngjobid)      ' check if task scheduled     if lngwin32apiresultcode = nerr_success         msgbox "task" & lngjobid & " has been scheduled."     end if  end sub private sub setstructvalue(udtatinfo at_info)     dim strtime string     dim strdate() string     dim vntweek() variant     dim intcounter integer     dim intweekcounter integer      vntweek = array("m", "t", "w", "th", "f", "s", "su")      udtatinfo          ' change format of time         strtime = format(text2.text, "hh:mm")          ' change time 1 used api         .jobtime = (hour(strtime) * 3600 + minute(strtime) * 60) * 1000          ' set date parameters         if val(text3.text) > 0              ' set task run on specific days of month i.e. 9th & 22nd of month             strdate = split(text3.text, ",")             intcounter = 0 ubound(strdate)                 .daysofmonth = .daysofmonth + 2 ^ (strdate(intcounter) - 1)             next          else              ' set task run on sepecific days of week i.e. monday & thursday             strdate = split(text3.text, ",")             intcounter = 0 ubound(strdate)                 intweekcounter = 0 ubound(vntweek)                     if ucase(strdate(intcounter)) = vntweek(intweekcounter)                         .daysofweek = .daysofweek + 2 ^ intweekcounter                         exit                     end if                 next             next         end if          ' set interactive property         if check1.value = vbunchecked             .flags = .flags or job_noninteractive         end if          ' set run periodically         if option2.value = true             .flags = .flags or job_run_periodically         end if          ' set command run         .command = strconv(text4.text, vbunicode)     end end sub 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -