Modul'deki Function'i buton ile çalıştırma.
#1
Elimde aşağıda gördüğünüz dosya ismini formdaki bir unbound text box'a kaydeden bir kod mevcut. Bu kodu modBrwsforXLS adıyla bir modül olarak kayıt ettim. (Kod test modunda çalışıyor.)

Sorum ise bu modüldeki GetOpenFile isimli Function'ı formdaki bir butonla nasıl ilişkilendirebilirim? (On Click)

Visual Basic
  1. Option Compare Database
  2.  
  3. ' This code was originally written by Ken Getz.
  4. ' It is not to be altered or distributed, 'except as part of an application.
  5. ' You are free to use it in any application,
  6. ' provided the copyright notice is left unchanged.
  7. '
  8. ' Code originally courtesy of:
  9. ' Microsoft Access 95 How-To
  10. ' Ken Getz and Paul Litwin
  11. ' Waite Group Press, 1996
  12. ' Revised to support multiple files:
  13. ' 28 December 2007
  14.  
  15. Type tagOPENFILENAME
  16. lStructSize As Long
  17. hwndOwner As Long
  18. hInstance As Long
  19. strFilter As String
  20. strCustomFilter As String
  21. nMaxCustFilter As Long
  22. nFilterIndex As Long
  23. strFile As String
  24. nMaxFile As Long
  25. strFileTitle As String
  26. nMaxFileTitle As Long
  27. strInitialDir As String
  28. strTitle As String
  29. Flags As Long
  30. nFileOffset As Integer
  31. nFileExtension As Integer
  32. strDefExt As String
  33. lCustData As Long
  34. lpfnHook As Long
  35. lpTemplateName As String
  36. End Type
  37.  
  38. Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
  39. Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
  40.  
  41. Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _
  42. Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean
  43. Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
  44.  
  45. Global Const ahtOFN_READONLY = &H1
  46. Global Const ahtOFN_OVERWRITEPROMPT = &H2
  47. Global Const ahtOFN_HIDEREADONLY = &H4
  48. Global Const ahtOFN_NOCHANGEDIR = &H8
  49. Global Const ahtOFN_SHOWHELP = &H10
  50. ' You won't use these.
  51. 'Global Const ahtOFN_ENABLEHOOK = &H20
  52. 'Global Const ahtOFN_ENABLETEMPLATE = &H40
  53. 'Global Const ahtOFN_ENABLETEMPLATEHANDLE = &H80
  54. Global Const ahtOFN_NOVALIDATE = &H100
  55. Global Const ahtOFN_ALLOWMULTISELECT = &H200
  56. Global Const ahtOFN_EXTENSIONDIFFERENT = &H400
  57. Global Const ahtOFN_PATHMUSTEXIST = &H800
  58. Global Const ahtOFN_FILEMUSTEXIST = &H1000
  59. Global Const ahtOFN_CREATEPROMPT = &H2000
  60. Global Const ahtOFN_SHAREAWARE = &H4000
  61. Global Const ahtOFN_NOREADONLYRETURN = &H8000
  62. Global Const ahtOFN_NOTESTFILECREATE = &H10000
  63. Global Const ahtOFN_NONETWORKBUTTON = &H20000
  64. Global Const ahtOFN_NOLONGNAMES = &H40000
  65. ' New for Windows 95
  66. Global Const ahtOFN_EXPLORER = &H80000
  67. Global Const ahtOFN_NODEREFERENCELINKS = &H100000
  68. Global Const ahtOFN_LONGNAMES = &H200000
  69. Function GetOpenFile(Optional varDirectory As Variant, _
  70. Optional varTitleForDialog As Variant) As Variant
  71.  
  72. ' Here's an example that gets an Access database name.
  73. Dim strFilter As String
  74. Dim lngFlags As Long
  75. Dim varFileName As Variant
  76.  
  77. ' Specify that the chosen file must already exist,
  78. ' don't change directories when you're done
  79. ' Also, don't bother displaying
  80. ' the read-only box. It'll only confuse people.
  81. lngFlags = ahtOFN_FILEMUSTEXIST Or _
  82. ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR
  83. If IsMissing(varDirectory) Then
  84. varDirectory = ""
  85. End If
  86. If IsMissing(varTitleForDialog) Then
  87. varTitleForDialog = ""
  88. End If
  89.  
  90. ' Define the filter string and allocate space in the "c"
  91. ' string Duplicate this line with changes as necessary for
  92. ' more file templates.
  93. strFilter = ahtAddFilterItem(strFilter, _
  94. "Excel File (*.xlsx)", "*.xlsx;*.xls")
  95.  
  96. ' Now actually call to get the file name.
  97. varFileName = ahtCommonFileOpenSave( _
  98. OpenFile:=True, _
  99. InitialDir:=varDirectory, _
  100. Filter:=strFilter, _
  101. Flags:=lngFlags, _
  102. DialogTitle:=varTitleForDialog)
  103. If Not IsNull(varFileName) Then
  104. varFileName = TrimNull(varFileName)
  105. End If
  106. GetOpenFile = varFileName
  107. Forms!frm_File_Tools![Text3] = varFileName
  108. End Function
  109. Private Function TrimNull(ByVal strItem As String) As String
  110. Dim intPos As Integer
  111.  
  112. intPos = InStr(strItem, vbNullChar)
  113. If intPos > 0 Then
  114. TrimNull = Left(strItem, intPos - 1)
  115. Else
  116. TrimNull = strItem
  117. End If
  118. End Function
  119. Private Function FixPath(ByVal path As String) As String
  120. If Right$(path, 1) <> "\" Then
  121. FixPath = path & "\"
  122. Else
  123. FixPath = path
  124. End If
  125. End Function





  Alıntı
Bu mesajı beğenenler:
#2
Merhaba;

Sayın spawnss örneğinizi eklerseniz size daha iyi yardımcı olabiliriz, örnekteki referansları görmekte fayda var.
"Amacımız; zorlaştırmak değil, kolaylaştırmak..." Abdullah Uğur
bayrak



  Alıntı
Bu mesajı beğenenler:
#3
Örneği ekte görebilirsiniz.

Asıl amacım kullanıcıya import edeceği dosyayı seçtirmek. Seçilen dosya ismi unbound textbox'ta belirecek ve ondan sonrasında TransferSpreadSheet komutu textbox'daki variable'ı kullanarak seçilmiş olan Excel dosyasını import edecek.


Eklenti Dosyaları
.rar   FileTools.rar (Boyut: 25,57 KB / İndirilme: 106)



  Alıntı
Bu mesajı beğenenler:
#4
Sayın spawnss;

Örneğiniz ektedir, inceleyiniz...

Kolay gelsin...


Eklenti Dosyaları
.rar   IMPORT-UM.rar (Boyut: 36,7 KB / İndirilme: 139)
"Amacımız; zorlaştırmak değil, kolaylaştırmak..." Abdullah Uğur
bayrak



  Alıntı
Bu mesajı beğenenler:
#5
Çok teşekkür ederim. Benim düşündüğümden de detaylı bir çalışma olmuş.

Ben sorunumu çözdüm. Başka bir modulde aynı function adı kullanıldığı için Access algılayamıyormuş. Function adını değiştirip onclick komutuna da sadece function adını yazınca sorun ortadan kalktı.

Tekrar çok teşekkür ederim.



  Alıntı
Bu mesajı beğenenler:


Benzer Konular...
Konu: Yazar Cevaplar: Gösterim: Son Mesaj
  [FORM] Ana Form Ve Alt Formdaki Checkbox'lı Alanlardaki Verileri Buton Ile Null Yapmak. M_Kemal_Askeri 4 127 01-05-2026, 16:30
Son Mesaj: M_Kemal_Askeri
  [FORM] Page Down Page Up Basıldığıdan Yordam çalıştırma atyaty 6 393 06-01-2026, 08:31
Son Mesaj: atyaty
  Buton Adlarının Tablodan Gelmesi alikagan 17 1.773 29-10-2023, 01:09
Son Mesaj: dsezgin
access-sql-18 [VBA] Buton Ile Referans Ekleme BeyTor 2 432 18-09-2023, 03:17
Son Mesaj: BeyTor
  Tablolarımı Tablo Böl Ile Böldüm, Programı Başka Bir Pc De çalıştırma Sorunu. programmer67 5 662 18-07-2023, 14:43
Son Mesaj: onur_can
  [FORM] 2 Ekranlı Bilgisayarda Access çalıştırma hedefkaya 4 496 02-02-2023, 16:29
Son Mesaj: hedefkaya
  Buton Ve/veya Mouse Makro Yazımı Hk. adnnfrm 1 431 31-01-2023, 22:54
Son Mesaj: BeyTor
  [FORM] Tabloda Boş Alanlara Buton Ile Kayıt Ekleme SümeyyeK 8 733 09-12-2022, 11:11
Son Mesaj: SümeyyeK

Foruma Git:


Bu konuyu görüntüleyen kullanıcı(lar): 1 Ziyaretçi