[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Custom control limits size so cannot select value

Asked by running32 in Access Forms, Access Coding/Macros

Can someone please tell me why the code below limits the number of records allowed to be added to the listbox. I can only select up to 32766 and then the by val is blank in the access form.   The error occurs when at value 32767 and the cdlDialogFailure is set to 32768 but if I change it makes no difference.  I was playing about with the file sizes but to tell the truth I have no idea why this is happening.  thank you for your help

Thanks

Private Sub OLEControl0_ItemClick(ByVal Item As Object)
MsgBox (Item)
 txtPatientId = Trim(Right$(Item.Key, Len(Item.Key) - 1))
 txtLN = Item.Text
 txtFN = Item.SubItems(1)
 txtMN = Item.SubItems(3)
 txtPT = Item.SubItems(4)
 txtIcon = Item.Icon

End Sub
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:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
636:
637:
638:
639:
640:
641:
642:
643:
644:
645:
646:
647:
648:
649:
650:
651:
652:
653:
654:
655:
656:
657:
658:
659:
660:
661:
662:
663:
664:
665:
666:
667:
668:
669:
670:
671:
672:
673:
674:
675:
676:
677:
678:
679:
680:
681:
682:
683:
684:
685:
686:
687:
688:
689:
690:
691:
692:
693:
694:
695:
696:
697:
698:
699:
700:
701:
702:
703:
704:
705:
706:
707:
708:
709:
710:
711:
712:
713:
714:
715:
716:
717:
718:
719:
720:
721:
722:
723:
724:
725:
726:
727:
728:
729:
730:
731:
732:
733:
734:
735:
736:
737:
738:
739:
740:
741:
742:
743:
744:
745:
746:
747:
748:
749:
750:
751:
752:
753:
754:
755:
756:
757:
758:
759:
760:
761:
762:
763:
764:
765:
766:
767:
768:
769:
770:
771:
772:
773:
774:
775:
776:
777:
778:
779:
780:
781:
782:
783:
784:
785:
786:
787:
788:
789:
790:
791:
792:
793:
794:
795:
796:
797:
798:
799:
800:
801:
802:
803:
804:
805:
806:
807:
808:
809:
810:
811:
812:
813:
814:
815:
816:
817:
818:
819:
820:
821:
822:
823:
824:
825:
826:
827:
828:
829:
830:
831:
832:
833:
834:
835:
836:
837:
838:
839:
840:
841:
842:
843:
844:
845:
846:
847:
848:
849:
850:
851:
852:
853:
854:
855:
856:
857:
858:
859:
860:
861:
862:
863:
864:
865:
866:
867:
868:
869:
870:
871:
872:
873:
874:
875:
876:
877:
878:
879:
880:
881:
882:
883:
884:
885:
886:
887:
888:
889:
890:
891:
892:
893:
894:
895:
896:
897:
898:
899:
900:
901:
902:
903:
904:
905:
906:
907:
908:
909:
910:
911:
912:
913:
914:
915:
916:
917:
918:
919:
920:
921:
922:
923:
924:
925:
926:
927:
928:
929:
930:
931:
932:
933:
934:
935:
936:
937:
938:
939:
940:
941:
942:
943:
944:
945:
Option Explicit
 
' From Access 2000 Developer's Handbook, Volume I
' by Getz, Litwin, and Gilbert. (Sybex)
' Copyright 1999. All rights reserved.
'
' Provide access to the File Open/Save,
' Color and Font common dialogs.
' Works similarly to the CommonDialog
' ActiveX control, but adds more features,
' and doesn't implement Printer or Help
' support.
 
' NOTE: This class module contains
' some redundant code (that is, code
' copied from other modules) so that
' it can be imported and used in other
' applications without needing to
' also import any subsidiary modules.
 
' =================
' API Constants
' =================
Private Const HWND_DESKTOP = 0
Private Const LF_FACESIZE = 32
Private Const FNERR_BUFFERTOOSMALL = &H3003
 
' Modify the Open/Save dialog box.
Private Const WM_USER = &H400
Private Const CDM_FIRST = (WM_USER + 100)
 
' =================
' API Enums (values defined by API,
' Enums defined here). These are set
' up to match the CommonDialog ActiveX
' control's constants, but we've added
' some extras.
' =================
 
Public Enum adhCDFontType
    RASTER_FONTTYPE = &H1
    DEVICE_FONTTYPE = &H2
    TRUETYPE_FONTTYPE = &H4
    BOLD_FONTTYPE = &H100
    ITALIC_FONTTYPE = &H200
    REGULAR_FONTTYPE = &H400
    SCREEN_FONTTYPE = &H2000
    PRINTER_FONTTYPE = &H4000
    SIMULATED_FONTTYPE = &H8000
    OPENTYPE_FONTTYPE = &H10000
    TYPE1_FONTTYPE = &H20000
    DSIG_FONTTYPE = &H40000
End Enum
 
Public Enum adhFontFaceAPI
    ANSI_CHARSET = 0
    DEFAULT_CHARSET = 1
    SYMBOL_CHARSET = 2
    SHIFTJIS_CHARSET = 128
    HANGEUL_CHARSET = 129
    GB2312_CHARSET = 134
    CHINESEBIG5_CHARSET = 136
    OEM_CHARSET = 255
    JOHAB_CHARSET = 130
    HEBREW_CHARSET = 177
    ARABIC_CHARSET = 178
    GREEK_CHARSET = 161
    TURKISH_CHARSET = 162
    VIETNAMESE_CHARSET = 163
    THAI_CHARSET = 222
    EASTEUROPE_CHARSET = 238
    RUSSIAN_CHARSET = 204
    MAC_CHARSET = 77
    BALTIC_CHARSET = 186
End Enum
 
Public Enum adhColorConstants
    cdlCCFullOpen = 2
    cdlCCHelpButton = 8
    cdlCCPreventFullOpen = 4
    cdlCCRGBInit = 1
    cdlCCAnyColor = &H100
    cdlCCEnableHook = &H10
    cdlCCSolidColor = &H80
End Enum
 
Public Enum adhErrorConstants
  '  cdlAlloc = 32752
    cdlAlloc = 45000
    cdlBufferTooSmall = 20476
   ' cdlCancel = 32755
   cdlCancel = 45000
    cdlCreateICFailure = 28661
    'Matches Number
    'cdlDialogFailure = -32768
      cdlDialogFailure = -45000
      cdlDndmMismatch = 28662
   '' cdlFindResFailure = 32761
    cdlFindResFailure = 45000
    cdlGetDevModeFail = 28666
    cdlGetNotSupported = 394
  ''  cdlHelp = 32751
  cdlHelp = 45000
    cdlInitFailure = 28665
    'cdlInitialization = 32765
    cdlInitialization = 45000
    cdlInvalidFileName = 20477
    cdlInvalidPropertyValue = 380
    cdlInvalidSafeModeProcCall = 680
    cdlLoadDrvFailure = 28667
   ' cdlLoadResFailure = 32760
   cdlLoadResFailure = 45000
  ''  cdlLoadStrFailure = 32762
  cdlLoadStrFailure = 45000
  ''  cdlLockResFailure = 32759
    cdlLockResFailure = 45000
  ''  cdlMemAllocFailure = 32758
  cdlMemAllocFailure = 45000
 '' cdlMemLockFailure = 32757
 cdlMemLockFailure = 45000
   cdlNoDefaultPrn = 28663
 cdlNoDevices = 28664
   cdlNoFonts = 24574
   ''cdlNoInstance = 32763
   cdlNoInstance = 45000
 '' cdlNoTemplate = 32764
  cdlNoTemplate = 45000
  cdlParseFailure = 28669
  cdlPrinterCodes = 28671
 cdlPrinterNotFound = 28660
    cdlRetDefFailure = 28668
   cdlSetNotSupported = 383
  cdlSetupFailure = 28670
  cdlSubclassFailure = 20478
 
End Enum
 
Public Enum adhFileOpenConstants
    cdlOFNAllowMultiselect = 512
    cdlOFNCreatePrompt = 8192
    cdlOFNEnableHook = 32
    cdlOFNEnableSizing = 8388608
    cdlOFNExplorer = 524288
    cdlOFNExtensionDifferent = 1024
    cdlOFNFileMustExist = 4096
    cdlOFNHelpButton = 16
    cdlOFNHideReadOnly = 4
    cdlOFNLongNames = 2097152
    cdlOFNNoChangeDir = 8
    cdlOFNNoDereferenceLinks = 1048576
    cdlOFNNoLongNames = 262144
    cdlOFNNoNetworkButton = 131072
    
   ' cdlOFNNoReadOnlyReturn = 32768
    cdlOFNNoReadOnlyReturn = 37500
    cdlOFNNoValidate = 256
    cdlOFNOverwritePrompt = 2
    cdlOFNPathMustExist = 2048
    cdlOFNReadOnly = 1
    cdlOFNShareAware = 16384
End Enum
 
Public Enum adhFontsConstants
    cdlCFANSIOnly = &H400
    cdlCFApply = &H200
    cdlCFBoth = &H3
    cdlCFEffects = &H100
    cdlCFEnableHook = &H8
    cdlCFFixedPitchOnly = &H4000
    cdlCFForceFontExist = &H10000
    cdlCFInitToLogFontStruct = &H40
    cdlCFLimitSize = &H2000
    cdlCFNoFaceSel = &H80000
    cdlCFNoSimulations = &H1000
    cdlCFNoSizeSel = &H200000
    cdlCFNoStyleSel = &H100000
    cdlCFNoVectorFonts = &H800
    cdlCFNoVertFonts = &H1000000
    cdlCFPrinterFonts = &H2
    cdlCFScalableOnly = &H20000
    cdlCFScreenFonts = &H1
    cdlCFShowHelp = &H4
    cdlCFTTOnly = &H40000
    cdlCFUseStyle = &H80
    cdlCFWYSIWYG = &H8000       ' must also have cdlCFScreenFonts & cdlCFPrinterFonts
End Enum
 
' You can use these values in the
' File Open/Save callback function
' to modify the text or visibility
' of any of the controls on the
' dialog. See the example callback
' function for a demo.
Public Enum adhFileOpenSaveControls
    fosCurrentFolder = &H471
    fosCurrentFolderLabel = &H443
    fosContentsList = &H460
    fosContentsListLabel = &H440
    fosSelectedFile = &H480
    fosSelectedFileLabel = &H442
    fosFilterList = &H470
    fosFilterListLabel = &H441
    fosReadOnly = &H410
    fosOKButton = 1
    fosCancelButton = 2
    fosHelpButton = &H40E
End Enum
 
Public Enum adhCommonDialogManage
    CDM_SETCONTROLTEXT = (CDM_FIRST + &H4)
    CDM_HIDECONTROL = (CDM_FIRST + &H5)
End Enum
 
' =================
' API Types
' =================
Private Type LOGFONT
    lfHeight As Long
    lfWidth As Long
    lfEscapement As Long
    lfOrientation As Long
    lfWeight As Long
    lfItalic As Byte
    lfUnderline As Byte
    lfStrikeOut As Byte
    lfCharSet As Byte
    lfOutPrecision As Byte
    lfClipPrecision As Byte
    lfQuality As Byte
    lfPitchAndFamily As Byte
    lfFaceName(1 To LF_FACESIZE) As Byte
End Type
 
Private Type ChooseColor
    lStructSize As Long
    hWndOwner As Long
    hInstance As Long
    rgbResult As Long
    lpCustColors As Long
    Flags As adhColorConstants
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type
 
Private Type OPENFILENAME
    lStructSize As Long
    hWndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    Flags As adhFileOpenConstants
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type
 
Private Type ChooseFont
    lStructSize As Long
    hWndOwner As Long          '  caller's window handle
    hdc As Long                '  printer DC/IC or NULL
    lpLogFont As Long
    iPointSize As Long         '  10 * size in points of selected font
    Flags As adhFontsConstants    '  enum. type flags
    rgbColors As Long          '  returned text color
    lCustData As Long          '  data passed to hook fn.
    lpfnHook As Long           '  ptr. to hook function
    lpTemplateName As String   '  custom template name
    hInstance As Long          '  instance handle of.EXE that
                               '    contains cust. dlg. template
    lpszStyle As String        '  return the style field here
                               '  must be LF_FACESIZE or bigger
    nFontType As Integer       '  same value reported to the EnumFonts
                               '    call back with the extra FONTTYPE_
                               '    bits added
    MISSING_ALIGNMENT As Integer
    nSizeMin As Long           '  minimum pt size allowed &
    nSizeMax As Long           '  max pt size allowed if
                                   '    CF_LIMITSIZE is used
End Type
 
' =================
' API Declarations
' =================
Private Declare Function GetDC _
 Lib "USER32" _
 (ByVal hWnd As Long) As Long
 
Private Declare Function ReleaseDC _
 Lib "USER32" _
 (ByVal hWnd As Long, ByVal hdc As Long) As Long
 
Private Const LOGPIXELSY = 90
Private Declare Function GetDeviceCaps _
 Lib "gdi32" _
 (ByVal hdc As Long, ByVal nIndex As Long) As Long
 
Private Declare Function MulDiv _
 Lib "kernel32" _
 (ByVal nNumber As Long, ByVal nNumerator As Long, _
 ByVal nDenominator As Long) As Long
 
Private Declare Function CommDlgExtendedError _
 Lib "comdlg32.dll" () As Long
 
Private Declare Function ChooseFont _
 Lib "comdlg32.dll" Alias "ChooseFontA" _
 (pChoosefont As ChooseFont) As Long
 
Private Declare Function ChooseColor _
 Lib "comdlg32.dll" Alias "ChooseColorA" _
 (pChoosecolor As ChooseColor) As Long
 
Private Declare Function GetOpenFileName _
 Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
 (pOpenfilename As OPENFILENAME) As Long
 
Private Declare Function GetSaveFileName _
 Lib "comdlg32.dll" Alias "GetSaveFileNameA" _
 (pOpenfilename As OPENFILENAME) As Long
 
' =================
' Storage for property values.
' =================
 
' Returns/sets the size of the file name
' buffer to use for the FileOpen dialog box.
' The default size is 1000.
Public FileNameBufferSize As Long
 
' Returns/sets the custom file open/save filter.
' Public CustomFilter As String
 
' Returns/sets the default filename extension for the dialog box.
Public DefaultExt As String
 
' Sets the string displayed in the title bar of the dialog box.
Public DialogTitle As String
 
' Returns/sets the path and filename of a selected file.
Public FileName As String
 
 ' Returns/sets the name (without the path) of the file to open or save at run time.
 Public FileTitle As String
 
' Returns/sets the filters that are displayed in the Type list box of a dialog box.
Public Filter As String
 
' Returns/sets a default filter for an Open or Save As dialog box.
Public FilterIndex As Long
 
' Returns/sets the initial file directory.
Public InitDir As String
 
' Returns/sets the selected color.
Public Color As Long
 
' Sets the hWnd of the dialog owner.
Public hWndOwner As Long
 
' Sets/Returns the character set.
' Although interesting, doesn't correspond
' to any property in the host app.
Public FontScript As adhFontFaceAPI
 
' Text describing the selected font style.
Public FontStyle As String
 
' Set/Returns the minimum and maximum font sizes,
' if you've set the cdlCFLimitSize flag.
' Disregarded otherwise.
Public Min As Integer
Public Max As Integer
 
' Returns the selected font color.
Public FontColor As Long
 
' Flag settings (for backwards compatability only)
Public Flags As Long
 
' Flags specific to the specific dialog box.
Public FontFlags As adhFontsConstants
Public ColorFlags As adhColorConstants
Public OpenFlags As adhFileOpenConstants
 
' Address of the callback function.
Public CallBack As Long
 
' Specifies the name of the font that appears in each row for the given level.
Public FontName As String
 
' Indicates whether an error is generated when the user chooses the Cancel button.
Public CancelError As Boolean
 
' Returns/sets italic font styles.
Public FontItalic As Boolean
 
' Returns/sets bold font styles. Included for
' backwards compatability. Use FontWeight
' instead.
Public FontBold As Boolean
 
' Font weight, from 100 to 900 (in multiples of 100)
' 700 is bold, 400 is normal.
Public FontWeight As Long
 
' Specifies the size (in points) of the font that appears in each row for the given level.
Public FontSize As Single
 
' Returns/sets strikethrough font styles.
Public FontStrikeThrough As Boolean
 
' Returns/sets underline font styles.
Public FontUnderline As Boolean
 
' Retrieve the font type, from the adhCDFontType
' list of options. Can be any number of
' items from the group, OR'd together.
Private mlngFontType As adhCDFontType
 
' Retrieve the 16 user-defined colors
' returned from the color chooser dialog.
Private malngColors(0 To 15) As Long
 
' Retrieve the offset within the full file name
' to the file portion, or the extension portion.
Private mlngFileOffset As Long
Private mlngFileExtOffset As Long
 
' Retrieve the list of files selected
' if cdlOFNAllowMultiSelect flag
' is set. If not, this array contains
' only the path, and single file selected.
Private mastrFileList() As String
 
Public Property Get FileList() As String()
    ' Get the parsed list of files.
    ' If there are items in this list,
    ' the 0th element is the path, and the
    ' rest are the selected files.
    ' Even if you only select a single
    ' file, we populate this array.
    FileList = mastrFileList
End Property
 
Public Property Get FileOffset() As Long
    ' Returns the offset within the full file name
    ' to the file portion.
    FileOffset = mlngFileOffset
End Property
 
Public Property Get FileExtOffset() As Long
    ' Returns the offset within the full file name
    ' to the file portion.
    FileExtOffset = mlngFileExtOffset
End Property
 
Public Property Get CustomColors() As Long()
    ' Return the array of custom colors.
    CustomColors = malngColors
End Property
 
Public Property Let CustomColors(Value() As Long)
    Dim i As Integer
    
    ' The array passed in must be indexed from
    ' 0 to 15. If not, weird things are going
    ' to happen -- we just copy from those
    ' indexes directly over.
    On Error GoTo HandleErrors
    For i = 0 To 15
        malngColors(i) = Value(i)
NextValue:
    Next i
    
ExitHere:
    Exit Property
    
HandleErrors:
    Resume NextValue
End Property
 
Public Property Get FontType() As adhCDFontType
    FontType = mlngFontType
End Property
 
' =================
' CommonDlg Methods
' =================
Public Sub ShowColor()
    
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
    ' Displays the CommonDialog control's Color dialog box.
    
    Dim cc As ChooseColor
    
    Call SetColorProperties(cc)
    If ChooseColor(cc) <> 0 Then
        Call GetColorProperties(cc)
    Else
        ' If the user wants to raise an error for the Escape
        ' do it now.
        If CancelError Then
            Err.Raise cdlCancel, , "Cancel was selected."
        End If
    End If
End Sub
 
Public Sub ShowFont()
    
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
    ' Display the CommonDialog control's Font dialog box
    
    Dim cf As ChooseFont
    Dim lf As LOGFONT
    Dim strStyle As String
    
    ' Arbitrarily allow 100 characters
    ' for the style string.
    strStyle = Space(100)
    Call SetFontProperties(cf, lf, strStyle)
    If ChooseFont(cf) <> 0 Then
        ' The user pressed the OK button
        Call GetFontProperties(cf, lf)
    Else
        ' If the user wants to raise an error for the Escape
        ' do it now.
        If CancelError Then
            Err.Raise cdlCancel, , "Cancel was selected."
        End If
    End If
End Sub
 
Public Sub ShowOpen()
    
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
    ' Displays the CommonDialog control's Open dialog box.
    
    Dim ofn As OPENFILENAME
    Dim lngErr As Long
    
    Call SetOpenProperties(ofn)
    If GetOpenFileName(ofn) <> 0 Then
        Call GetOpenProperties(ofn)
    Else
        lngErr = CommDlgExtendedError()
        Select Case lngErr
            Case FNERR_BUFFERTOOSMALL
                Err.Raise cdlBufferTooSmall, , _
                 "Filename buffer is too small for the selected files."
            Case 0
                ' If the user wants to raise an error for the Escape
                ' do it now.
                If CancelError Then
                    Err.Raise cdlCancel, , "Cancel was selected."
                End If
            Case Else
                Err.Raise lngErr, , "Unexpected error."
        End Select
    End If
End Sub
 
Public Sub ShowSave()
    
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
    ' Displays the CommonDialog control's Save As dialog box.
    
    Dim ofn As OPENFILENAME
    Dim lngErr As Long
    
    Call SetOpenProperties(ofn)
    If GetSaveFileName(ofn) <> 0 Then
        Call GetOpenProperties(ofn)
    Else
        lngErr = CommDlgExtendedError()
        Select Case lngErr
            Case FNERR_BUFFERTOOSMALL
                Err.Raise cdlBufferTooSmall, , "Filename buffer is too small for the selected files."
            Case 0
                ' If the user wants to raise an error for the Escape
                ' do it now.
                If CancelError Then
                    Err.Raise cdlCancel, , "Cancel was selected."
                End If
            Case Else
                Err.Raise lngErr, , "Unexpected error."
        End Select
    End If
End Sub
 
Private Sub SetOpenProperties(ofn As OPENFILENAME)
    
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
    
    ' Copy object properties into the data
    ' structure before calling the API.
    
    Dim strFileName As String
    Dim strFileTitle As String
  
    ' Show the Open common dialog.
    ' Allocate string space for the returned strings.
    strFileName = String(FileNameBufferSize, vbNullChar)
    LSet strFileName = FileName & vbNullChar
    strFileTitle = String$(1024, vbNullChar)
    
    With ofn
        .lStructSize = Len(ofn)
        .hWndOwner = hWndOwner
        ' The API doesn't want those "|" things, it wants
        ' vbNullChar, with an extra one on the end.
        .lpstrFilter = Replace(Trim$(Filter), "|", vbNullChar) & vbNullChar
        .nFilterIndex = FilterIndex
        .lpstrFile = strFileName
        
        .nMaxFile = Len(strFileName)
        .lpstrFileTitle = strFileTitle
        .nMaxFileTitle = Len(strFileTitle)
        .lpstrTitle = DialogTitle
        
        ' You can set either the OpenFlags
        ' or general Flags properties. We'll
        ' OR them together. If you use both, you'd
        ' better know what you're doing!
        ' In addition, we're going to assume that you
        ' always want the explorer-style interface.
        ' Can't imagine why you wouldn't, at this point.
        .Flags = OpenFlags Or Flags Or cdlOFNExplorer
        .lpstrDefExt = DefaultExt
        .lpstrInitialDir = InitDir
 
        ' We don't support the CustomFilter
        ' property, but you could add it in
        ' if you like. This buffer
        ' must contain at least 40 characters
        ' to make WinNT happy.
        .lpstrCustomFilter = String(40, vbNullChar)
        .nMaxCustFilter = Len(.lpstrCustomFilter)
        
        If .Flags And cdlOFNEnableHook Then
            .lpfnHook = CallBack
        End If
    End With
End Sub
 
Private Sub GetOpenProperties(ofn As OPENFILENAME)
    
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
        
    ' Retrieve properties from the API structure
    ' back into properties of this object.
    
    Dim astrFileInfo() As String
    Dim intPos As Integer
    Dim strFileName As String
    
    With ofn
        FileName = .lpstrFile
        OpenFlags = .Flags
        Flags = .Flags
        FileTitle = .lpstrFileTitle
        FilterIndex = .nFilterIndex
        mlngFileExtOffset = .nFileExtension
        mlngFileOffset = .nFileOffset
        ' CustomFilter = .lpstrCustomFilter
        If .nFileOffset > 0 Then
            strFileName = .lpstrFile
            If Mid$(strFileName, mlngFileOffset, 1) = vbNullChar Then
                ' Look for trailing double null chars, and trim
                ' the string there.
                intPos = InStr(1, strFileName, vbNullChar & vbNullChar)
                If intPos > 0 Then
                    strFileName = Left$(strFileName, intPos - 1)
                End If
                astrFileInfo = Split(strFileName, vbNullChar)
                mastrFileList = astrFileInfo
            Else
                ' Only a single file selected,
                ' so break it up into path and file
                ' portion, as if the user had selected
                ' multiple files.
                ReDim mastrFileList(0 To 1)
                mastrFileList(0) = Left$(strFileName, mlngFileOffset - 1)
                mastrFileList(1) = adhTrimNull(Mid$(strFileName, mlngFileOffset + 1))
                FileName = adhTrimNull(FileName)
            End If
        End If
    End With
End Sub
 
Private Sub SetColorProperties(cc As ChooseColor)
    
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
    
    ' Copy object properties into the data
    ' structure before calling the API.
    
    cc.lStructSize = LenB(cc)
    cc.hWndOwner = hWndOwner
    cc.rgbResult = Color
    cc.lpCustColors = VarPtr(malngColors(0))
    
    ' You can set either the ColorFlags
    ' or general Flags properties. We'll
    ' OR them together. If you use both, you'd
    ' better know what you're doing!
    cc.Flags = ColorFlags Or Flags
    
    ' This had better be the address of
    ' a public function in a standard
    ' module, or you're going down!
    ' Use the adhFnPtrToLong procedure
    ' to convert from AddressOf to
    ' long.
    If cc.Flags And cdlCCEnableHook Then
        cc.lpfnHook = CallBack
    End If
End Sub
 
Private Sub GetColorProperties(cc As ChooseColor)
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
        
    ' Retrieve properties from the API structure
    ' back into properties of this object.
    
    Color = cc.rgbResult
End Sub
 
Private Sub SetFontProperties( _
 cf As ChooseFont, lf As LOGFONT, strStyle As String)
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
    
    ' Copy object properties into the data
    ' structure before calling the API.
    
    On Error Resume Next
    Dim lngFlags As Long
    
    cf.lStructSize = LenB(cf)
    If Len(FontName) > 0 Then
        Call adhSetFaceName(lf, FontName)
    End If
    cf.lpLogFont = VarPtr(lf)
    cf.hWndOwner = hWndOwner
    cf.lpszStyle = FontStyle
        
    lf.lfHeight = CalcHeightFromPoints()
    lf.lfStrikeOut = FontStrikeThrough
    lf.lfUnderline = FontUnderline
    lf.lfItalic = FontItalic
    lf.lfCharSet = FontScript
    
    If FontWeight = 0 Then
        If FontBold Then
            lf.lfWeight = 700
        Else
            lf.lfWeight = 400
        End If
    Else
        lf.lfWeight = FontWeight
    End If
    
    cf.rgbColors = FontColor
    cf.nSizeMax = Max
    cf.nSizeMin = Min
    
    ' You can set either the FontFlags
    ' or general Flags properties. We'll
    ' OR them together. If you use both, you'd
    ' better know what you're doing!
    ' We also OR in cdlCFInitToLogFontStruct,
    ' 'cause you generally want to do that.
    
    ' In addition, if the user hasn't specified
    ' either/both cdlCFPrinterFonts or cdlCFScreenFonts
    ' we're going to assume they want both.
    lngFlags = Flags Or FontFlags
    If Not (lngFlags And cdlCFPrinterFonts) And _
     Not (lngFlags And cdlCFScreenFonts) Then
        lngFlags = lngFlags Or cdlCFBoth
    End If
    cf.Flags = lngFlags Or cdlCFInitToLogFontStruct
    
    ' This had better be the address of
    ' a public function in a standard
    ' module, or you're going down!
    ' Use the adhFnPtrToLong procedure
    ' to convert from AddressOf to
    ' long.
    If cf.Flags And cdlCFEnableHook Then
        cf.lpfnHook = CallBack
    End If
End Sub
 
Private Sub GetFontProperties(cf As ChooseFont, lf As LOGFONT)
    
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
    ' Retrieve properties from the API structure
    ' back into properties of this object.
    
    On Error Resume Next
    FontName = adhTrimNull(StrConv(lf.lfFaceName, vbUnicode))
    FontColor = cf.rgbColors
    FontItalic = lf.lfItalic
    FontBold = ((cf.nFontType And BOLD_FONTTYPE) <> 0)
    FontWeight = lf.lfWeight
    FontSize = cf.iPointSize \ 10
    FontStrikeThrough = lf.lfStrikeOut
    FontUnderline = lf.lfUnderline
    FontScript = lf.lfCharSet
    FontStyle = adhTrimNull(cf.lpszStyle)
    mlngFontType = cf.nFontType
End Sub
 
Private Function CalcHeightFromPoints() As Long
    
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
    Dim hdc As Long
    Dim lngLogPixelsY As Long
    
    On Error GoTo HandleErrors
    
    ' Assume an invalid value for failure.
    CalcHeightFromPoints = 0
    
    ' Convert from points back to the internal
    ' device units value.
    hdc = GetDC(HWND_DESKTOP)
    If hdc <> 0 Then
        lngLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY)
        CalcHeightFromPoints = _
         -1 * MulDiv(CInt(FontSize), lngLogPixelsY, 72)
    End If
 
ExitHere:
    Exit Function
 
HandleErrors:
    Resume ExitHere
End Function
 
Private Sub Class_Initialize()
    ' Assume the default size.
   ' FileNameBufferSize = 20000
   FileNameBufferSize = 50000
End Sub
 
Private Function adhTrimNull(strVal As String) As String
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    
    ' Trim the end of a string, stopping at the first
    ' null character.
    
    Dim intPos As Integer
    intPos = InStr(1, strVal, vbNullChar)
    Select Case intPos
        Case Is > 1
            adhTrimNull = Left$(strVal, intPos - 1)
        Case 0
            adhTrimNull = strVal
        Case 1
            adhTrimNull = vbNullString
    End Select
End Function
 
Private Sub adhSetFaceName(lf As LOGFONT, strValue As String)
    
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert. (Sybex)
    ' Copyright 1999. All rights reserved.
    '
    ' Given a string, get it back into the ANSI byte array
    ' contained within a LOGFONT structure.
    
    Dim intLen As Integer
    Dim intI As Integer
    Dim abytTemp() As Byte
    
    On Error GoTo HandleErrors
    
    abytTemp = StrConv(strValue, vbFromUnicode)
    intLen = UBound(abytTemp) + 1
    
    ' Make sure the string isn't too long.
    If intLen > LF_FACESIZE - 1 Then
        intLen = LF_FACESIZE - 1
    End If
    For intI = 1 To intLen
        lf.lfFaceName(intI) = abytTemp(intI - 1)
    Next intI
    ' Tack on a final Chr$(0).
    lf.lfFaceName(intI) = 0
    
ExitHere:
    Exit Sub
    
HandleErrors:
    Resume ExitHere
End Sub
[+][-]06/10/08 12:17 PM, ID: 21754148Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Access Forms, Access Coding/Macros
Sign Up Now!
Solution Provided By: jimhorn
Participating Experts: 2
Solution Grade: A
 
[+][-]06/10/08 12:21 PM, ID: 21754193Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06/10/08 01:46 PM, ID: 21754899Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_EXPERT_20070906