PDA

View Full Version : حرفه ای: تعيين محدوديت براي فيلدهاي attachment به لحاظ نوع و سايز و تعداد فايلهاي الصاقي



majid6363
یک شنبه 05 مرداد 1393, 14:34 عصر
با سلام؛ من يه ديتابيس ايجاد كردم با استفاده از اكسس 2007 و قراره اونو به دهها نفر بدم و بعد از پركردنش برگردونن به من. نگراني من اينه كه چون فيلدهاي attachment داره اولا نوع فايلي رو كه من ميخوام نداده باشن و مجبور باشم دونه دونه چك كنم
دوما اندازه فايلاي الصاقي انقد زياد باشه كه براي يكپارچه سازي در ديتابيس اصلي خودم به مشكل بر بخورم
سوماً ممكنه بجاي يه فايل تو هر فيلد، چند تا فايل فرستاده باشند كه اين براي بررسي اسناد ارسالي كار من رو مشكل ميكنه
لطفا يكي راهنمايي كنه كه چطور ميتونم براي يك فيلد از نوع attachment سه محدوديت بالارو بذارم
لطفاً يه فايل نمونه براي بذارين
ممنون

majid6363
دوشنبه 06 مرداد 1393, 08:14 صبح
من يه سري دستورات پيدا كردم از اينترنتكه نميدونم ازش تو فايل اكسس چطور استفاده كنم و چطور به جداول، فرم ها و ريپورت ها و ... مرتبطش كنم. لطفا كمك كنيد.
Option Compare Database


Public Function SelectFileWithSizeCheck() As String
'Got this from experts exchange and this Checks the File as well as selets the Attachment
'in here you can filter for both size and type of attachment DD 11\13\09
'Requires Office XP (2002) or higher
'Requires references to the Microsoft Office Object Library and
'the Scripting Runtime Library
'Created by Helen Feddema 24-Oct-2009
'Last modified 24-Oct-2009
On Error GoTo ErrorHandler
Dim fd As Office.FileDialog
Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File
Dim varSelectedItem As Variant
Dim lngFileSize As Long
lngFileSize = 10485760

'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd
'Set AllowMultiSelect to True to allow selection of multiple files
.AllowMultiSelect = True
.Title = "Browse for File"
.ButtonName = "Select"
.Filters.Clear
.Filters.add "Documents", "*.*", 1
.InitialView = msoFileDialogViewDetails
If .Show = -1 Then
'Get selected item in the FileDialogSelectedItems collection
'Have to use collection even if just one item is selected
For Each varSelectedItem In .SelectedItems
strFileNameAndPath = CStr(varSelectedItem)
Next varSelectedItem
Else
Debug.Print "User pressed Cancel"
strFileNameAndPath = ""
End If
End With
If strFileNameAndPath = "" Then
Exit Function
Else

Set fil = fso.GetFile(strFileNameAndPath)

'Check File Size
Debug.Print "File size: " & fil.Size
If fil.Size <= lngFileSize Then
SelectFileWithSizeCheck = strFileNameAndPath
Else
MsgBox "File exceeds the allowed size; can't import"
SelectFileWithSizeCheck = ""
strFileNameAndPath = ""
End If


ErrorHandlerExit:
Set fd = Nothing
Exit Function


ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit


End If

End Function




Public Function AddAttachment() As String
'Procedure to add attachments DD 11\13\09


On Error GoTo Err_AddImage


Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2


Set db = CurrentDb
Set rsParent = Me.Recordset


rsParent.Edit


Set rsChild = rsParent.Fields("Attachment").Value

'get path of attachment to be added
rsChild.AddNew
rsChild.Fields("FileData").LoadFromFile (strFileNameAndPath)


rsChild.Update
rsParent.Update


Exit_AddImage:


Set rsChild = Nothing
Set rsParent = Nothing
Exit Function


Err_AddImage:


If Err = 3820 Then
MsgBox ("File already part of the contract!")
Resume Next


Else
MsgBox "Some Other Error occured!", Err.Number, Err.Description
Resume Exit_AddImage


End If


End Function


Public Function OpenFirstAttachmentAsTempFile(ByRef rstCurrent As DAO.Recordset, ByVal strFieldName As String) As String
'This will open the attachment in a Temp file and the user has to manually save it if the want it. DD 11\13\09
'Recordset for complex type
Dim rstComplex As DAO.Recordset2


'Get the recordset of the attachment
Set rstComplex = Me.Recordset!Attachment.Value
'Find the current document displayed
rstComplex.FindFirst "FileName = '" & Me.lstAttachment.Value & "'"
'If current file found
If Not rstComplex.NoMatch Then






Dim fldAttach As DAO.Field2
Dim strFilePath As String
Dim strTempDir As String
'--- Get the Temp directory from the environment variable.
strTempDir = Environ("Temp")
'--- Make sure the path always ends with a backslash.
If Right(strTempDir, 1) <> "\" Then strTempDir = strTempDir & "\"
'--- Append the name of the attached file to temp dir.
strFilePath = strTempDir & rstComplex.Fields("FileName").Value
If Dir(strFilePath) <> "" Then
'--- the file already exists--delete it first.
'--- remove any file attributes (e.g. read-only) that would block the kill command.
VBA.SetAttr strFilePath, vbNormal
VBA.Kill strFilePath ' delete the file.
End If
'--- export the file now
Set fldAttach = rstComplex.Fields("FileData")
fldAttach.SaveToFile strFilePath
rstComplex.Close ' cleanup
'--- Use Windows Explorer to launch the file.
VBA.Shell "Explorer.exe " & Chr(34) & strFilePath & Chr(34), vbNormalFocus
Else
MsgBox "Can't Find the Current Document to Show.", vbInformation
End If
Set rstComplex = Nothing


End Function

majid6363
شنبه 11 مرداد 1393, 07:36 صبح
يكي جواب بده لطفا من گير كردم سر همين موضوع......................... لطفا.......................

mohammadsaleh
دوشنبه 13 مرداد 1393, 19:38 عصر
من تعجب مي كنم از اين نحو سئوال كردن دوستان. شما خودتون بهتر مي دونيد كار با كدها چقدر زحمت داره اونوقت چطور بدون قراردادن حداقل نمونه اي كوچك انتظار داريد ديگران كمك شما بكنند

majid6363
سه شنبه 14 مرداد 1393, 09:05 صبح
با سلام خدمت آقا محمد. اين درخواست خيلي تو اينترنت مطرح شده كه تحت عنوان attachment control, limit attachment size و ...كه برخي جواب دادن و برخي جواب ندادن كه از داخل هيچ كدومشون چيزي مثل فايلهاي accdb كه تو اين سايت يعني (برنامه نويس) مطرح ميشه پيدا نشده. من يه فايل ميذارم كه ميخوام براي قسمت attachmnt (اصل مدرك) محدوديت سايز، نوع و تعداد بذارم. فكر كنم منظورتون همين بود كه حداقل يك نمونه بگذارم تو پيامم. لطفاً اگه ممكنه اين فايل رو اصلاح كنيد.ممنون و تشكر

majid6363
چهارشنبه 22 مرداد 1393, 11:17 صبح
يعني هيچ كسي توي اين سايت و آموزشگاه .... نميتونه كمكم كنه؟