克服 VBA 输入框字符限制

发布于 2024-09-04 07:07:12 字数 81 浏览 5 评论 0原文

我当前用来收集文本 InputBox 的函数显然不能接受超过 255 个字符,并且我需要能够收集更多字符?是否可以使用参数或不同的函数来增加此限制?

The current function I use to collect text InputBox can't accept more than 255 characters apparently, and I need to be able to collect more than that? Is there a parameter or different function I can use to increase this limit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

很糊涂小朋友 2024-09-11 07:07:12

迂腐一点,输入框允许您输入最多 255 个字符,但它只会返回 254 个字符。

除此之外,是的,您需要创建一个带有文本框的简单表单。然后做一些“辅助函数”,比如:

Function getBigInput(prompt As String) As String
    frmBigInputBox.Caption = prompt
    frmBigInputBox.Show
    getBigInput = frmBigInputBox.txtStuff.Text
End Function

或者类似的东西......

To be pedantic, the Inputbox will let you type up to 255 characters, but it will only return 254 characters.

Beyond that, yes, you'll need to create a simple form with a textbox. Then just make a little "helper function" something like:

Function getBigInput(prompt As String) As String
    frmBigInputBox.Caption = prompt
    frmBigInputBox.Show
    getBigInput = frmBigInputBox.txtStuff.Text
End Function

or something like that...

寒尘 2024-09-11 07:07:12

感谢 BradC 提供的信息。我的最终代码大致如下,我有一个按钮,可以调用我创建的表单并将其定位一点,因为我在第一次使用后每次都遇到表单位于错误位置的问题。

Sub InsertNotesAttempt()
    NoteEntryForm.Show
    With NoteEntryForm
        .Top = 125
        .Left = 125
    End With
End Sub

用户窗体是一个文本框和两个命令按钮(取消和确定)。按钮的代码如下:

Private Sub CancelButton_Click()
    Unload NoteEntryForm
End Sub

Private Sub OkButton_Click()
    Dim UserNotes As String

    UserNotes = NotesInput.Text

    Application.ScreenUpdating = False
    If UserNotes = "" Then
        NoteEntryForm.Hide
        Exit Sub
    End If

    Worksheets("Notes").ListObjects("Notes").ListRows.Add (1)
    Worksheets("Notes").Range("Notes").Cells(1, 1) = Date
    Worksheets("Notes").Range("Notes").Cells(1, 2) = UserNotes
    Worksheets("Notes").Range("Notes").Cells(1, 2).WrapText = True
    ' Crap fix to get the wrap to work. I noticed that after I inserted another row the previous rows
    ' word wrap property would kick in. So I just add in and delete a row to force that behaviour.
    Worksheets("Notes").ListObjects("Notes").ListRows.Add (1)
    Worksheets("Notes").Range("Notes").Item(1).Delete
    NotesInput.Text = vbNullString
    NotesInput.SetFocus ' Retains focus on text entry box instead of command button.
    NoteEntryForm.Hide
    Application.ScreenUpdating = True
End Sub

Thanks BradC for the info that. My final code was roughly as follows, I have a button that calls the form that I created and positions it a bit as I was having some issues with the form being in the wrong spot the everytime after the first time I used.

Sub InsertNotesAttempt()
    NoteEntryForm.Show
    With NoteEntryForm
        .Top = 125
        .Left = 125
    End With
End Sub

The userform was a TextBox and two CommandButtons(Cancel and Ok). The code for the buttons was as follows:

Private Sub CancelButton_Click()
    Unload NoteEntryForm
End Sub

Private Sub OkButton_Click()
    Dim UserNotes As String

    UserNotes = NotesInput.Text

    Application.ScreenUpdating = False
    If UserNotes = "" Then
        NoteEntryForm.Hide
        Exit Sub
    End If

    Worksheets("Notes").ListObjects("Notes").ListRows.Add (1)
    Worksheets("Notes").Range("Notes").Cells(1, 1) = Date
    Worksheets("Notes").Range("Notes").Cells(1, 2) = UserNotes
    Worksheets("Notes").Range("Notes").Cells(1, 2).WrapText = True
    ' Crap fix to get the wrap to work. I noticed that after I inserted another row the previous rows
    ' word wrap property would kick in. So I just add in and delete a row to force that behaviour.
    Worksheets("Notes").ListObjects("Notes").ListRows.Add (1)
    Worksheets("Notes").Range("Notes").Item(1).Delete
    NotesInput.Text = vbNullString
    NotesInput.SetFocus ' Retains focus on text entry box instead of command button.
    NoteEntryForm.Hide
    Application.ScreenUpdating = True
End Sub
空名 2024-09-11 07:07:12

我没有足够的代表来发表评论,但在助手的子 form_load 中,您可以添加:

me.AutoCenter = True

在该表单之外,您可以这样做:

NoteEntryForm.Show
Forms("NoteEntryForm").AutoCenter = True

当我在工作中从两个额外的监视器中走出来时,我的 Access 表单变得非常混乱我家里有一台额外的显示器,有时会迷失在角落里。这个 AutoCenter 已将其纳入我的每一个表单的表单属性中。

I don't have enough rep to comment, but in the sub form_load for the helper you can add:

me.AutoCenter = True

Outside of that form, you can do it like this:

NoteEntryForm.Show
Forms("NoteEntryForm").AutoCenter = True

My Access forms get all confused when I go from my two extra monitors at work to my one extra monitor at home, and are sometimes lost in the corner. This AutoCenter has made it into the form properties of every one of my forms.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文