Accessã§æ¡ä»¶ä»ãã°ã«ãŒãåããäœã£ãŠã¿ã
äŒæ¥ãåŠæ ¡ãå人ãããããã®ã·ãŒã³ã«æŒããŠäžå®ã®éèŠãããã®ããã°ã«ãŒãåããã人ã®çåãã ãã§ãªããç©åã®ã°ã«ãŒãã³ã°ãªã©ã«æŒããŠäžå®ã®æ¡ä»¶ã®å ã°ã«ãŒãåããããäœæ¥ã¯ã人éãè¡ããšé«ç¢ºçã§å€±æããŸãã
ããããèªåã®éèŠã«ãã£ãã°ã«ãŒãåãããã°ã©ã ã¯èªåã§äœããããããŸãããããã§ä»åç ä¿®äŒåå è ãäžå®æ¡ä»¶ã«åºã¥ããŠçåããããšããããã°ã©ã ãäœæããŸããã
ç®æ¬¡
ä»å䜿çšãããã¡ã€ã«
- ã°ã«ãŒãåãããã°ã©ã - Access2016ã§äœæïŒ64bitïŒ
- æ¥çšè¡šãã³ãã¬ãŒã - äžèšã®ããã°ã©ã ã«ã忢±ã®excelã·ãŒã
â»æ¥çšè¡šãã³ãã¬ãŒãã«åå è æ å ±ãèšè¿°ããŠãAccessåŽã«ã€ã³ããŒãããä»çµã¿ã«ãªã£ãŠããŸããã°ã«ãŒãåãã¯AccessåŽã§è¡ãããŸãã
äºåæºåãšæ¡ä»¶
ããã°ã©ã ã®æºå
ãã®ããã°ã©ã ã¯ä»¥äžã®åç §èšå®ãå©çšããŠããŸããä»ã©ãã®ç°å¢ã§è¿œå ããªããã°ãªããªããšãããã®ã¯ç¡ããšæããŸãã®ã§ãéåžžã¯ç¹ã«äœãããå¿ èŠã¯ãããŸããïŒèªåã§æ§ç¯ããå Žåãé€ãïŒ
- Microsoft Office 15.0 Object Library - ãªãã³ã®æ§ç¯ã§äœ¿çšããŠããŸãã
- Microsoft Scripting Runtime - ãã¡ã€ã«ã®æç¡ãªã©æ§ã ãªã·ãŒã³ã§å©çšããŠããŸãã
- ActiveX Data Object 2.8 Library - ExcelããŒã¿ã®æžãåºãæã«ä»åå©çšããŠããŸãã
ãŸããæå·åZIP圢åŒã§ã®ããã¯ã¢ããã»åŸ©å ã®çºã«ã7-zip64.dllãå©çšããŠããŸãïŒãã¡ã€ã«ã«å梱ïŒã
å³ïŒã©ã€ãã©ãªã®åç §ãå¿ èŠ
æ¥çšè¡šã®æºå
æ¥çšè¡šãã³ãã¬ãŒãã«ããŒã¿ã®è¿œèšãå¿ èŠã§ããæ¬ããã°ã©ã ã¯ãã®æ¥çšè¡šãåã蟌ãã§ãã°ã«ãŒãåããããããã°ã©ã ãšãã圢ã«ããŠãããããäºåã«ããŒã¿ã®æºåãå¿ èŠã«ãªããŸãã
ããŒã¿ã¯ããŒãã«åœ¢åŒã«ãªã£ãŠãããä»åå©çšããåã¯ä»¥äžã®éãã
- äŒç€ŸNoïŒæ°å€ïŒ
- äŒç€ŸåïŒæååïŒ
- éšçœ²ïŒæååïŒ
- æ¥çš®ïŒæååïŒ
- å§_挢åïŒæååïŒ
- å_挢åïŒæååïŒ
- å§_å šè§ã«ãïŒæååïŒ
- å_å šè§ã«ãïŒæååïŒ
- å¹Žéœ¢ïŒæ°å€ïŒ
- æ§å¥ïŒæååïŒ - ç· or 女
åçš®ã³ãŒãã·ãŒãã¯ãã¡ã€ã³ã®åè¬è ãªã¹ãã®å ¥åãå©ããããã®ãã®ãªã®ã§ãç¹ã«æŽåã¯ãããšãè¯ãã§ãããããŒã¿ã®å ¥åèŠåãvlookup颿°ã§ã®åç §ãªã©ã§å©çšãããšè¯ãã§ãããã
ã°ã«ãŒãåãæ¡ä»¶
ä»åã®ããã°ã©ã ã§ã¯æ¯ãåããæ¡ä»¶ãåºå®ã§ã¯ãªããããã€ãã¯ãªãã·ã§ã³ã§éžã¹ãããã«äœæããŠããŸããåºå®ã®æ¡ä»¶ãšããŠã¯äººæ°ãã§ãã¯ãšç·å¥³æ¯ãã§ãã¯ã¯å¿ ãå®è¡ããããã«ããŠããŸãïŒã€ãŸãã1ããŒã æå®ã®äººæ°ãè¶ ããŠãããïŒç·å¥³æ¯ãçŽååã«ãªã£ãŠããã©ããïŒïŒã
- ãªãã³ã®ã°ã«ãŒãåãâã¢ããªã®èšå®ãéã
- ã¢ããªã®èšå®ãã€ã¢ãã°å ã®ãã¢ããªã®èšå®ãã¿ããéã
- æ¯ãåããªãã·ã§ã³ã§ããã«æ¯ãåãæ¡ä»¶ãå ãããå Žåã«ã¯ãã§ãã¯ãå ¥ãã
- ã°ã«ãŒã人æ°ã¯ã1ããŒã åœããã®äººæ°ã§ããæ¥çšè¡šåå è ããã®æ°å€ã§å²ã£ãå€ãã°ã«ãŒãã®æ°ã«ãªããŸãã
- å¹Žéœ¢æ§æãã§ãã¯ã¯ãå šäœã®äžå€®å€ïŒå¹³åå€ã§ã¯ãªãïŒã«è¿ããªãããã«ãæ¯ãåãããŒã å ã®å¹Žéœ¢æ§æãèæ ®ããŠãããŒã ã«å ããèšå®ã§ãã
- åå§ãã§ãã¯ã¯ãåãå§ãæã€ãã®ã¯ãªãã¹ãäžç·ã«ããªãããã«ããçºã®èšå®ã§ãã
- åäŒæ¥ãã§ãã¯ã¯ãè€æ°äŒç€Ÿåå ã®æ¯ãåããããéã«ãåãããŒã å ã«åãäŒç€Ÿã®äººéãäžç·ã«ããªãçºã®èšå®ã§ãã
- åæ¥çš®ãã§ãã¯ã¯ãè€æ°äŒç€Ÿåå ã®æ¯ãåããããéã«ãåãããŒã å ã«åãæ¥çš®ã®äººéãäžç·ã«ããªãçºã®èšå®ã§ãã
- åéšçœ²ãã§ãã¯ã¯ãåãããŒã å ã«åãéšçœ²ã®äººéãäžç·ã«ããªãçºã®èšå®ã§ãã
- å¹Žéœ¢æ§æãã§ãã¯ããªã³ã«ãããšãããªãã¹ãè¿ãæ³ããšãããªãã·ã§ã³ã䜿ããŸãããã®ãªãã·ã§ã³ã¯è¿œå æã®ããŒã å æå°å¹Žéœ¢ã®äžäž2æ³ãŸã§ãããŒã ã«è¿œå å¯ãšãããšããæ¡ä»¶ã«å€æŽããçºã®ãã®ã§ãã
- ä¿åãæŒããšsettingããŒãã«ã«ãªãã·ã§ã³èšå®ãä¿åãããŸãã
æ¯ãåãã«ã¯ä¹±æ°ãå©çšããã°ã«ãŒãæ°åã®ã³ãŒããå²ãæ¯ãããããã«ãªã£ãŠããŸãããæ¡ä»¶ã«ãã£ãŠã¯å¿ ãããæ¡ä»¶éãã®æ¯ãåããã§ãããšã¯éããŸããããã®å Žåããã¶ãã人ã¯å床ã人æ°ãã§ãã¯ãšç·å¥³æ¯ãã§ãã¯ã ãã§ã©ããã®ããŒã ã«ãã蟌ãããã«ããã°ã©ã ãããŠããŸããæ¡ä»¶ã«ãã¶ãã人ããã蟌ãã§ãã®ã§ãæ¡ä»¶éãã«ãªã£ãŠããªãããŒã ãçºçããŸãã
äœãããã§ããã¶ããã±ãŒã¹ããããŸãããã®å Žåæ¯ãåã倱æãšãªããŸãããä¹±æ°ã䜿ã£ãŠãã®ã§ãå床æ¯ãåãå®è¡ãè¡ãã°ããŸãããäºããããŸãã
äœ¿ãæ¹
äœ¿ãæ¹èªäœã¯éåžžã«åçŽã§ãã
- åè¬è ãªã¹ãã®ã€ã³ããŒããã¯ãªãã¯ããçšæããæ¥çšè¡šãã³ãã¬ãŒããèªã¿èŸŒãŸããŠããŒã¿ãåã蟌ã¿ãŸãïŒæŽãæ¿ããªã®ã§ãæ°ããããŒã¿ãåã蟌ããšå€ãããŒã¿ã¯åé€ãããŸãïŒ
- ã°ã«ãŒãåãå®è¡ãè¡ããšãã¢ããªã®èšå®ã«ãŠã»ããããæ¡ä»¶ã«åºã¥ããŠå€å®ããããŒã å²ãè¡ããŸãã
- ã°ã«ãŒãåããå®äºãããšã°ã«ãŒãåãçµæãã©ãŒã ã衚瀺ãããããŒã å å¹³å幎霢ã人æ°ãããããã®äººéã®å€ã衚瀺ãããŸãã
- ã°ã«ãŒãåãåºåãã¯ãªãã¯ãããšãæå®ã®å Žæã«åè¬è ãªã¹ããšããŠåããçµæããœãŒãããããŒã¿ãExcel圢åŒã§åºåããŠãããŸãã
ZIPããã¯ã¢ãããæŽ»çšãããšãã»ããããæ¡ä»¶ããã®æã®çµæãªã©ãããŒãããŠããã埩å ã§å ã«æ»ããããã«ãªã£ãŠããŸããããã€ã詊ããŠã¿ãŠçŽåŸã®è¡ããã¿ãŒã³ã«ãªã£ãããåºåããŠã¿ããšè¯ãã§ãããã
ãœãŒã¹ã³ãŒã
ã°ã«ãŒãåããå®è¡ããã³ãŒã
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
'ã°ã«ãŒãåããè¡ãã¡ã€ã³ã«ãŒãã³ Public Function groupin() '倿°ã®å®£èš Dim alluser As Integer 'å
šãŠãŒã¶æ° Dim mbrlimit As Integer '1ããŒã ãããäººæ° Dim grpcount As Integer 'ã°ã«ãŒãæ° Dim avgage As Double 'å
šãŠãŒã¶å¹³å幎霢 Dim insflg As Boolean '远å ããŠããããã©ã° Dim i As Long Dim cnt As Long mbrlimit = DLookup("å€", "setting", "ID=1") 'ã°ã«ãŒã人æ°èšå®ãååŸ cnt = 1 Dim result As Variant Dim checkernum As Boolean Dim empid As Integer Dim danjolim As Integer Dim seibetsu As String Dim breaker As Integer breaker = 1 Dim targetage As Integer Dim firstname As String Dim compid As Integer Dim nejiko As Integer Dim gyouname As String Dim busyoname As String nejiko = 0 Dim ans As Integer '該åœã¬ã³ãŒããåŠçæžã¿ã«ãªã£ãŠãå Žååãåããããã result = MsgBox("åã蟌ãã ãªã¹ããå
ã«ã°ã«ãŒãåããå®è¡ããŸããïŒ", vbYesNo + vbDefaultButton2 + vbExclamation) If result = vbYes Then 'ã€ã³ããŒãåŠçãç¶è¡ãã Else 'ã¡ãã»ãŒãžã衚瀺 MsgBox "ããŒã¿ã®æŽæ°ããã£ã³ã»ã«ããŸããã" 'çµäºåŠç Exit Function End If 'DBæ¥ç¶çšå€æ° Dim db As DAO.Database Dim rst As DAO.Recordset Dim rse As DAO.Recordset Dim rso As DAO.Recordset Dim strSQL As Variant Set db = CurrentDb 'ããŒãã«ããŒã¿ãã¯ãªã¢ãã strSQL = "DELETE * FROM ã°ã«ãŒã" db.Execute strSQL strSQL = "DELETE * FROM ããŒã " db.Execute strSQL 'ã¬ã³ãŒãã»ãããã»ãããã Set rst = db.OpenRecordset("åè¬è
ãªã¹ããœãŒã") Set rse = db.OpenRecordset("ã°ã«ãŒã") Set rso = db.OpenRecordset("ããŒã ") 'ã°ã«ãŒãæ°ãšå¹³å幎霢ãååŸãã alluser = DCount("ID", "åè¬è
ãªã¹ã") grpcount = RoundUp(alluser / mbrlimit, 0) 'å°æ°ç¹ä»¥äžæ¡äžã avgage = CInt(DLookup("Median", "äžå€®å€")) 'å
šå¹³å幎霢 danjolim = RoundUp(mbrlimit / 2, 0) 'ã°ã«ãŒãããŒãã«ã«é£çªã§ã°ã«ãŒããçæ For i = 1 To grpcount With rse .AddNew !ã°ã«ãŒããã³ã㌠= cnt .Update End With 'ã«ãŠã³ã¿ãåã cnt = cnt + 1 Next i 'æ¡ä»¶å€å®ããŠåè¬è
IDãããŒã ããŒãã«ã«è¿œå ãã Dim teamavg As Variant Dim options As Variant Dim beforeflg As Integer Dim tempavgage As Integer beforeflg = 0 'æ¯ãåããªãã·ã§ã³ã®ååŸ Dim nencheck As Variant Dim doucheck As Variant Dim comcheck As Variant Dim induscheck As Variant Dim bucheck As Variant Dim naruage As Variant nencheck = DLookup("å€", "setting", "ID=2") doucheck = DLookup("å€", "setting", "ID=3") comcheck = DLookup("å€", "setting", "ID=4") induscheck = DLookup("å€", "setting", "ID=5") bucheck = DLookup("å€", "setting", "ID=6") naruage = DLookup("å€", "setting", "ID=7") Do Until rst.EOF 'ã«ãŠã³ã¿ã»ãã©ã°åæå breaker = 1 insflg = False 'åè¬è
IDãååŸãã empid = rst("ID") 'æ§å¥ãååŸãã seibetsu = rst("æ§å¥") seibetsu = Replace(seibetsu, "æ§", "") '幎霢ãååŸãã targetage = rst("幎霢") 'ååãååŸãã firstname = rst("å§_挢å") 'äŒç€ŸNoãååŸãã compid = rst("äŒç€ŸNo") 'æ¥çš®åãååŸãã gyouname = rst("æ¥çš®") 'éšçœ²åãååŸãã If IsNull(rst("éšçœ²")) Then busyoname = "" Else busyoname = rst("éšçœ²") End If 'ä¹±æ°åæå Randomize Do Until insflg = True '倿°åæå beforeflg = 0 'ã©ã³ãã ãªcntãçæ cnt = Int(grpcount * Rnd + 1) 'ã«ãŠã³ã¿ãæ¢å®å€ãè¶
ããŠããå Žåã«ã¯ããã°ã©ã ãçµäºããïŒç¡éã«ãŒã鲿¢ïŒ If breaker > grpcount Then Exit Do End If '人æ°ããªãããã«éããŠããªããã°true checkernum = checkman(mbrlimit, cnt) If checkernum = True Then 'ç·å¥³æ¯çã«NGãã©ããïŒ checkernum = danjocheck(danjolim, cnt, seibetsu) If checkernum = True Then '幎霢ãã§ãã¯éå§ options = nencheck If options = -1 Then 'ãªãã¹ãè¿ãæ³ãªãã·ã§ã³ã®æç¡ options = naruage If options = -1 Then 'ããŒã ã®æå°å¹Žéœ¢ãç®åº teamavg = DMin("幎霢", "ããŒã ", "ã°ã«ãŒããã³ããŒ=" & cnt) If IsNull(teamavg) Then 'ãã©ã°ãç«ãŠã beforeflg = beforeflg + 1 Else 'æå°å¹Žéœ¢ã®ååŸ2æ³ãŸã§ã察象ãšãã tempavgage = targetage - teamavg 'ãã€ãã¹å€ã®å Žåã¯ãã©ã¹å€ã«å€ãã If tempavgage < 0 Then tempavgage = tempavgage * -1 End If If tempavgage > 2 Then '幎霢ã2æ³è¶
ããŠãã®ã§NG Else 'OKãªã®ã§ãã©ã°ãç«ãŠã beforeflg = beforeflg + 1 End If End If Else 'åŸæ¥ã®å¹³åå¹Žéœ¢ã«æ²¿ã£ãæ¯ãåããå®è¡ '察象ã®ããŒã ã®å¹³å幎霢ãåºã teamavg = DAvg("幎霢", "ããŒã ", "ã°ã«ãŒããã³ããŒ=" & cnt) If IsNull(teamavg) Then teamavg = 0 End If '幎霢ã察象ãšãªããã®ãã©ããå€å® checkernum = agecheck(avgage, CDbl(teamavg), targetage) If checkernum = True Then beforeflg = beforeflg + 1 End If End If Else beforeflg = beforeflg + 1 End If 'åéšçœ²ãã§ãã¯éå§ options = bucheck If options = -1 Then '幎霢ã察象ãšãªããã®ãã©ããå€å® checkernum = bumoncheck(busyoname, cnt) If checkernum = True Then beforeflg = beforeflg + 1 End If Else beforeflg = beforeflg + 1 End If 'åäŒæ¥ãã§ãã¯éå§ options = comcheck If options = -1 Then checkernum = compcheck(compid, cnt) If checkernum = True Then beforeflg = beforeflg + 1 End If Else beforeflg = beforeflg + 1 End If 'åæ¥çš®ãã§ãã¯éå§ options = induscheck If options = -1 Then checkernum = gyoucheck(gyouname, cnt) If checkernum = True Then beforeflg = beforeflg + 1 End If Else beforeflg = beforeflg + 1 End If 'åå§ãã§ãã¯éå§ options = doucheck If options = -1 Then checkernum = firstcheck(firstname, cnt) If checkernum = True Then beforeflg = beforeflg + 1 End If Else beforeflg = beforeflg + 1 End If 'beforeflgã®å€ã5ãªãã°è¿œå ãã If beforeflg = 5 Then 'ããŒã ã«ã¡ã³ããŒã远å ãã With rso .AddNew !ã°ã«ãŒããã³ã㌠= cnt !åè¬è
ID = empid !æ§å¥ = seibetsu !幎霢 = targetage !å§_挢å = firstname !äŒç€ŸNo = compid !æ¥çš® = gyouname !éšçœ² = busyoname .Update End With 'ãã©ã°ãç«ãŠã insflg = True End If End If End If 'breakerã«ãŠã³ããã¢ãã breaker = breaker + 1 Loop 'ãã®æç¹ã§insflgãfalseã®å Žåã©ããã®ããŒã ã«ãã蟌ãïŒãã¡ãžãŒå¯Ÿå¿ïŒ If insflg = False Then 'ãããã¿ã«ãŠã³ã远å nejiko = nejiko + 1 '倿°åæå breaker = 1 'ä¹±æ°åæå Randomize Do Until insflg = True 'ã©ã³ãã ãªcntãçæ cnt = Int(grpcount * Rnd + 1) 'ã«ãŠã³ã¿ãæ¢å®å€ãè¶
ããŠããå Žåã«ã¯ããã°ã©ã ãçµäºããïŒç¡éã«ãŒã鲿¢ïŒ If breaker > grpcount Then Exit Do End If '人æ°ããªãããã«éããŠããããã§ã㯠checkernum = checkman(mbrlimit, cnt) If checkernum = True Then 'ç·å¥³æ¯çã«NGãã©ããïŒãã§ã㯠checkernum = danjocheck(danjolim, cnt, seibetsu) If checkernum = True Then 'ããŒã ã«ã¡ã³ããŒããããã With rso .AddNew !ã°ã«ãŒããã³ã㌠= cnt !åè¬è
ID = empid !æ§å¥ = seibetsu !幎霢 = targetage !å§_挢å = firstname !äŒç€ŸNo = compid !æ¥çš® = gyouname !éšçœ² = busyoname .Update End With 'ãã©ã°ãç«ãŠã insflg = True End If End If 'breakerãã«ãŠã³ãã¢ãã breaker = breaker + 1 Loop 'æçµãã§ã㯠If insflg = False Then ans = MsgBox("æ¡ä»¶å³ãããŠãã ãã ã£ãã£ãœããã", vbOKOnly + vbCritical, "倱æïŒïŒ") Exit Function End If End If '次ã®ã¬ã³ãŒããžç§»åãã rst.MoveNext Loop 'ãã蟌ã¿ã«ãŠã³ã衚瀺 If nejiko = 0 Then Else ans = MsgBox(nejiko & "ä»¶ãããã¿ãŸããã", vbOKOnly + vbInformation, "ããžèŸŒã¿ä»¶æ°") End If 'çµäºåŠç ans = MsgBox("ããŒã åããå®äºããŸãã", vbOKOnly + vbInformation, "åŠçå®äº") DoCmd.OpenForm "ã°ã«ãŒãåãçµæ", acNormal, , , acFormEdit, acWindowNormal rst.Close rse.Close rso.Close Set rso = Nothing Set rse = Nothing Set rst = Nothing Set db = Nothing End Function '人æ°ãã§ãã¯ããã颿° Public Function checkman(ByVal limit As Integer, ByVal teamnum As Integer) As Boolean '察象ã®teamnumã®çŸåšã®æ æ°ããã§ã㯠Dim check As Variant check = DLookup("åè¬è
IDã®ã«ãŠã³ã", "人æ°ã«ãŠã³ã", "ã°ã«ãŒããã³ããŒ=" & teamnum) 'ã¡ã³ããŒæ°ããªãããã«éããŠãããã©ãã If check >= limit Then checkman = False Else checkman = True End If End Function 'ç·å¥³æ¯ããã§ãã¯ãã颿° Public Function danjocheck(ByVal limit As Integer, ByVal teamnum As Integer, ByVal sei As String) As Boolean '察象ã®teamnumã®çŸåšã®hanseiã®å€ãlimitã«éããŠããããã§ã㯠Dim check As Variant check = DCount("ID", "ããŒã ", "æ§å¥='" & sei & "' AND ã°ã«ãŒããã³ããŒ=" & teamnum) If check > limit - 1 Then 'ãªãããè¶
ããŠãã®ã§è¿œå ã ã danjocheck = False Else 'ãªãããéããŠããªãã®ã§OK danjocheck = True End If End Function '幎霢平åãã§ãã¯ããã颿° Public Function agecheck(ByVal allavg As Double, ByVal teamavg As Double, ByVal targetage As Integer) As Boolean '倿°ã®å®£èš Dim hantei As Boolean 'å
šå¹³åãšããŒã å¹³åã®æ¯èŒ If allavg >= teamavg Then 'ã¿ãŒã²ãããšããŒã å¹³åãæ¯èŒïŒé«ãæ¹ãå
¥ããïŒ If targetage >= teamavg Then hantei = True Else hantei = False End If Else 'ã¿ãŒã²ãããšããŒã å¹³åã®æ¯èŒïŒäœãæ¹ãå
¥ããïŒ If targetage >= teamavg Then hantei = False Else hantei = True End If End If 'å€å®çµæãè¿ã agecheck = hantei End Function 'åãå§ã®äººéããããã©ãããã§ãã¯ãã颿° Public Function firstcheck(ByVal firstname As String, ByVal teamnum As Integer) As Boolean '察象ã®teamnumã«æŒããŠãåå§ã®äººéãäœåãããïŒ Dim check As Variant check = DCount("ID", "ããŒã ", "å§_挢å='" & firstname & "' AND ã°ã«ãŒããã³ããŒ=" & teamnum) 'ã«ãŠã³ãã0ãªãã°true If check = 0 Then firstcheck = True Else firstcheck = False End If End Function 'äŒç€Ÿåã®éè€ããããã©ãããã§ãã¯ãã颿° Public Function compcheck(ByVal compid As Integer, ByVal teamnum As Integer) As Boolean '察象ã®teamnumã®çŸåšã®hanseiã®å€ãlimitã«éããŠããããã§ã㯠Dim check As Variant check = DCount("ID", "ããŒã ", "äŒç€ŸNo=" & compid & " AND ã°ã«ãŒããã³ããŒ=" & teamnum) 'ã«ãŠã³ãã0ãªãã°true If check = 0 Then compcheck = True Else compcheck = False End If End Function 'åãæ¥çš®ã®éè€ããããã©ããããã§ãã¯ãã颿° Public Function gyoucheck(ByVal gyouname As String, ByVal teamnum As Integer) As Boolean '察象ã®teamnumã«æå®ã®gyounameãå«ãŸããŠããä»¶æ°ããã§ã㯠Dim check As Variant check = DCount("ID", "ããŒã ", "æ¥çš®='" & gyouname & "' AND ã°ã«ãŒããã³ããŒ=" & teamnum) 'ã«ãŠã³ãã0ãªãã°true If check = 0 Then gyoucheck = True Else cgyoucheck = False End If End Function 'éšçœ²åã®éè€ããããã©ããããã§ãã¯ãã颿° Public Function bumoncheck(ByVal buname As String, ByVal teamnum As Integer) As Boolean '察象ã®teamnumã«æå®ã®gyounameãå«ãŸããŠããä»¶æ°ããã§ã㯠Dim check As Variant check = DCount("ID", "ããŒã ", "éšçœ²='" & buname & "' AND ã°ã«ãŒããã³ããŒ=" & teamnum) 'ã«ãŠã³ãã0ãªãã°true If check = 0 Then bumoncheck = True Else bumoncheck = False End If End Function |
- ã°ã«ãŒãããŒãã«ã¯æ¯ãåãåŸã®æ¯ãåãçµæã®èŠªããŒãã«ã§ããããŒã ããŒãã«ãããã«ã¶ãäžãããµãããŒãã«ãšãªããŸãã
- åè¬è ãªã¹ããœãŒãã¯ã¯ãšãªã§ãã人æ°ãå€ãé ã«äŒç€Ÿæ¯ã«ãœãŒãããŠããŸãïŒããããäºã§æ¯ãåãæåçãäžãããŸãïŒ
- ã°ã«ãŒãæ°ã¯åå è ç·æ°Ã·1ããŒã åœãã人æ°ã§ç®åºã
- å¹³å幎霢ãšãããŸãããå®éã«ã¯äžå€®å€ãå©çšããŠããŸããæ¯ãåãæã«ãå šäœäžå€®å€ããããŒã å¹³åå€ãäœãå Žåãé«ãå Žåãããããã«æŒããŠè¿œå ããããšããŠãè ã®å¹Žéœ¢ãæ¯èŒããŠè¿œå ãããïŒããªãããæ±ºå®ããŠããŸãã
- ç·å¥³æ¯ã®ç®åºã¯å šäœããç®åºã1ããŒã åœãã人æ°Ã·2ã§èšç®ããŠããŸãããç·å¥³æ¯ã1:1ã§ã¯ãªããããªã±ãŒã¹ã§ã¯ãããã®å å·¥ãå¿ èŠã«ãªããŸãã
- 察象è ã®è¿œå å¯åŠã®ãã©ã€åæ°ã¯ã°ã«ãŒãæ°ååè¡ãããã®å€å®çšã«breaker倿°ãçšæããŠãããbreakerããªãããã«éããããã«ãŒãã匷å¶é¢è±ããŸãã
- ãã§ãã¯é åºã¯ããæ¡ä»¶ãå³ããéè€å¯èœæ§ã®é«ãé ç®ããè¡ã£ãŠããŸãïŒã§ãªããšãæ¡ä»¶é©åå€ã倧éã«çºçããŠããŸãïŒã
- é çªã¯ã人æ°ãªããããã§ãã¯ãç·å¥³æ¯ãã§ãã¯ãéšçœ²ãã§ãã¯ãåéšçœ²ãã§ãã¯ãåäŒæ¥ãã§ãã¯ãåæ¥çš®ãã§ãã¯ãåå§ãã§ãã¯ã®é ã«è¡ã£ãŠããŸãã
- beforeflgã«å€ãå ç®ããäºã§ééãšããåèšå€ããªãã·ã§ã³é ç®ã®æ°ã®åèšã§ãã5ã«éãããããŒã ã«å ããããã«ããŠããŸãã
- ãã¶ããå Žåã2段éç®ãšããŠã人æ°ãªãããããç·å¥³æ¯ãã®ãã§ãã¯ã®ã¿ã§ééãšããããŒã ã«åŒ·å¶æ¯ãåãããããŠããŸãã
- ããã§ãNGã®å Žåã«ã¯ã倱æããšçåããããã°ã©ã ã¯åŒ·å¶çµäºããŸããäœããRnd颿°ã«ããã©ã³ãã ãªçæãªã®ã§ãå床ã®å®è¡ãæ¡ä»¶ã®ç·©åã«ãã£ãŠééããããã«ãªããããããŸããã
å®è¡çµæãExcelã·ãŒãã«æžãåºãã³ãŒã
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
'æ¯ãåãçµæããŒã¿ãExcel Automationã§åºåãã Public Function exportReport() Dim AppObj As Object 'Excel.Applicationãªããžã§ã¯ãã®å®£èš Dim WBObj As Object 'Excel.Workbookãªããžã§ã¯ãã®å®£èš Dim WsObj As Object 'Excel.WorkSheetãªããžã§ã¯ãã®å®£èš Dim WsObj2 As Object Dim FilePath As String Dim strFileName As Variant Dim dummyfile As String âDBæ¥ç¶çšã®å€æ° Dim dbs As Database Dim strSQL As String Set dbs = CurrentDb 'ã³ãã¯ã·ã§ã³ã確ç«ãã Dim con As New ADODB.Connection Dim rec As New ADODB.Recordset Set con = CurrentProject.Connection 'ãã¹ã¯ããããã©ã«ããååŸ Dim dPath As String, WSH As Variant Set WSH = CreateObject("WScript.Shell") dPath = WSH.SpecialFolders("Desktop") & "\" 'ä»®ã®ãã¡ã€ã«åãçæãã dummyfile = dPath & "åè¬è
管çã·ãŒã" 'ååãã€ããŠä¿åãã€ã¢ãã°ã衚瀺 strFileName = GetFileName(False, 'MicrosoftExcel ãã㯠(*.xlsx)|*.xlsx', '', dummyfile & '.xlsx') 'éžæçµæãè©äŸ¡ If strFileName = 0 Then 'ãã£ã³ã»ã«ãã¿ã³ãæŒããããšãã®åŠçãèšè¿° MsgBox "ãã£ã³ã»ã«ãããŸããã" Exit Function End If 'ãã³ãã¬ãã¡ã€ã«ãæå®ãã FilePath = CurrentProject.Path & "\export.xlsx" 'ãã¡ã€ã«ãè€è£œããïŒãã€ã¢ãã°äœ¿çšïŒ FileCopy FilePath, strFileName 'ãã¡ã€ã«ãéã Set AppObj = CreateObject("Excel.Application") 'å®è¡æãã€ã³ãã£ã³ã° Set WBObj = AppObj.Workbooks.Open(strFileName) 'ã¯ãŒã¯ããã¯ãéã Set WsObj = WBObj.Worksheets("äºåå±çšäŒç€Ÿé ") 'excelç»é¢ã®æŽæ°ããªãã«ãã AppObj.ScreenUpdating = False 'ç æèšã®ããŠã¹ãã€ã³ã¿ DoCmd.Hourglass True AppObj.Visible = True 'Excelã¢ããªã±ãŒã·ã§ã³ã衚瀺ãã AppObj.Calculation = xlManual 'åèšç®ã忢ãã 'ã¯ãŒã¯ã·ãŒããžã®åŠç 'Excelã«ãšã¯ã¹ããŒããããããŒãã«ã®ããŒã¿ãååŸ rec.Open "äºåå±çšäŒç€Ÿé ", con WsObj.Range("a2").CopyFromRecordset rec rec.Close Set WsObj = WBObj.Worksheets("äºåå±çš50é³é ") rec.Open "äºåå±çš50é³é ", con WsObj.Range("a2").CopyFromRecordset rec rec.Close Set WsObj = WBObj.Worksheets("äºåå±çšGé ") rec.Open "äºåå±çšGé ", con WsObj.Range("a2").CopyFromRecordset rec rec.Close Set WsObj = WBObj.Worksheets("åè¬è
çšGé ") rec.Open "åè¬è
çšGé ", con WsObj.Range("a2").CopyFromRecordset rec rec.Close 'åèšç®ã«æ»ã AppObj.Calculation = xlAutomatic AppObj.ScreenUpdating = True 'ç æèšã®ããŠã¹ãã€ã³ã¿ DoCmd.Hourglass False 'Excelãä¿åããŠéãã WBObj.Save 'ã¯ãŒã¯ããã¯ãä¿åãã WBObj.Close 'ã¯ãŒã¯ããã¯ãéãã AppObj.Quit 'çµäºåŠç Set AppObj = Nothing Set WBObj = Nothing Set WsObj = Nothing Set WsObj2 = Nothing 'ã¡ãã»ãŒãžè¡šç€º MsgBox "åè¬è
管çã·ãŒãããŒã¿ã®äœæãå®äºããŸããã" End Function Function GetFileName(OpenOrSaveFlg As Boolean, strFilter As String, _ strTitle As String, strDefaultPath As String) As String Dim returnValue As Integer Dim strFilePath As String strFilePath = strDefaultPath If strFilter = "" Then strFilter = "å
šãŠã®ãã¡ã€ã« (*.*)|*.*" End If WizHook.key = 51488399 'WIZHOOKæå¹ returnValue = WizHook.GetFileName( _ 0, "", strTitle, "", strFilePath, "", _ strFilter, _ 0, 0, 0, OpenOrSaveFlg _ ) WizHook.key = 0 ' WizHook ç¡å¹ If returnValue = 0 Then GetFileName = strFilePath Else GetFileName = 0 End If End Function 'å
šè§åè§ã«ã倿 Public Function kanahen(kanaword As String) As String kanahen = StrConv(kanaword, vbWide) End Function 'ãžããªã¹ããŒã¹é€å» Public Function cutspace(words As String) As String Dim temp As String 'å
šè§åè§ã®ã¹ããŒã¹é€å» temp = Replace(words, " ", "") temp = Replace(words, "ã", "") cutspace = temp End Function |
- ãã¹ã¯ããããã©ã«ããåæå€ãšããŠãexport.xlsxãã¡ã€ã«ãã³ããŒããããã«åºåããŸãã
- ããŒã å 容ããœãŒãããã¯ãšãªããããããCopyFromRecordsetã¡ãœããã§æå®ã®ã·ãŒãã«åºåããŸãã
- GetFileName颿°ã¯ãã¡ã€ã«ã®éžæçšãã€ã¢ãã°ãåºãããã®é¢æ°ã§ãã
- æã æå®ã®åã®æåã«åè§å šè§æ··åšããŠãã±ãŒã¹ãããã®ã§ãkanahenã«ãŠå šè§ã«ãã«çµ±äžããŠããŸãã
- æã æå®ã®åã®æåã«ã¹ããŒã¹ãæ··åšããŠãã±ãŒã¹ãããã®ã§ãcutspaceã«ãŠã¹ããŒã¹ã¯é€å»ããŠããŸãã
- ADOãšCopyFromRecordsetãããã°åæ§ã®ããŒã¿åºåã¯å¯èœãªã®ã§ãExcelåäœã§ãåºåç³»ã¯å®çµã¯å¯èœãšããã°å¯èœã§ãã