У меня в таблице есть столбец с длинным текстом, а в форме - многострочное текстовое поле. Мое текстовое поле настроено на открытие FileDialog и вставку полных путей, каждый в новой строке, к выбранным файлам. Вставка не работает, когда она многострочная, она пустая. Я тестировал одну строку, и она работает. Вот мой код VB:
Моя вставка:
Private Sub btn_test1_Click()
mSaved = True
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ctl As Control
Dim varItem As Variant
Dim i As Integer
On Error GoTo ErrorHandler
Set db = CurrentDb()
Set rs = db.OpenRecordset("TrainingLog", dbOpenDynaset, dbAppendOnly)
'make sure a selection has been made
If Me.ListBox_Emp.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 employee"
mSaved = False
Exit Sub
ElseIf Me.ddl_Topic.Value = 0 Then
MsgBox "Must select a topic"
mSaved = False
Exit Sub
ElseIf Me.ddl_Type.Value = 0 Then
MsgBox "Must select a category"
mSaved = False
Exit Sub
ElseIf Me.ddl_Source.Value = 0 Then
MsgBox "Must select a source"
mSaved = False
Exit Sub
ElseIf Me.ddl_mediaType.Value = 0 Then
MsgBox "Must select a media type"
mSaved = False
Exit Sub
ElseIf Me.ddl_Cert.Value = 0 Then
MsgBox "Must select either certificate, sign-in sheet, or both"
mSaved = False
Exit Sub
End If
'add selected value(s) to table
Set ctl = Me.ListBox_Emp
For Each varItem In ctl.ItemsSelected
rs.AddNew
rs!Employee = ctl.ItemData(varItem)
rs!Topic = Me.ddl_Topic.Value
rs!TopicOther = Me.txt_TopicOther.Value
rs!TitleOfTraining = Me.txt_Title.Value
rs!Category = Me.ddl_Type.Value
rs!CategoryOther = Me.txt_typeOther.Value
rs!MediaType = Me.ddl_mediaType.Value
rs!Source = Me.ddl_Source.Value
rs!SourceOther = Me.txt_sourceOther.Value
rs!DateCompleted = Me.DateCompleted.Value
rs!CertSignSheet = Me.ddl_Cert.Value
rs!MakeUp = Me.ChkBox_MakeUp.Value
rs!DateOriginal = Me.dt_DateOriginal.Value
rs!Mandatory = Me.ChkBox_Mandatory.Value
rs!DateDue = Me.dt_DueDate.Value
rs!DocumentLinks = Me.txt_DocumentLinks.Value
rs!Notes = Me.txt_Notes.Value
rs.Update
Next varItem
MsgBox ("Changes Saved!")
mSaved = False
If MsgBox("Do You Want to Log Another Training?", vbYesNo + vbQuestion) = vbYes Then
For i = 0 To ListBox_Emp.ListCount
If ListBox_Emp.Selected(i) = True Then
ListBox_Emp.Selected(i) = False
End If
Next i
ddl_Topic.Value = ""
txt_TopicOther.Value = ""
txt_Title.Value = ""
ddl_Type.Value = ""
txt_typeOther.Value = ""
ddl_mediaType.Value = ""
ddl_Source.Value = ""
txt_sourceOther.Value = ""
DateCompleted.Value = ""
ddl_Cert.Value = ""
ChkBox_MakeUp.Value = ""
dt_DateOriginal.Value = ""
ChkBox_Mandatory.Value = ""
dt_DueDate.Value = ""
txt_DocumentLinks.Value = ""
txt_Notes.Value = ""
Exit Sub
Else
DoCmd.Close acForm, "AddTrainingLog_noSub"
End If
ExitHandler:
Set rs = Nothing
Set db = Nothing
Exit Sub
ErrorHandler:
Select Case Err
Case Else
MsgBox Err.Description
DoCmd.Hourglass False
Resume ExitHandler
End Select
End Sub
Мой FileDialog:
Private Sub txt_DocumentLinks_Click()
Dim dlgOpen As FileDialog
Dim varFileName As String
Dim sFolder As String
Dim vrtSelectedItem As Variant
Dim myArray() As Variant
Dim myString As String
Dim x As Long
txt_DocumentLinks.Text = ""
Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = True
''Start in
.InitialFileName = "Y:\Data Dept"
.Show
For Each vrtSelectedItem In .SelectedItems
'Using a msgbox to test getting the path names, this is working great!
'MsgBox (vrtSelectedItem)
txt_DocumentLinks.Text = txt_DocumentLinks.Text '& vbCrLf & vrtSelectedItem
'sText = Replace(sText, vbLf & vbCr, "")
Next vrtSelectedItem
End With
End Sub