如何将Debug.print转换为Access中的列或文本字段?

时间:2016-04-06 16:26:11

标签: ms-access access-vba

有没有办法将Debug.print的结果打印到表单上的单元格而不是仅在立即窗口中打印? PS。我借用这段代码来生成密码。

Private Sub Command23_Click()
Dim s As String * 8 'fixed length string with 8 characters
Dim n As Integer
Dim ch As Integer 'the character
For n = 1 To Len(s) 'don't hardcode the length twice
    Do
        ch = Rnd() * 127 'This could be more efficient.
        '48 is '0', 57 is '9', 65 is 'A', 90 is 'Z', 97 is 'a', 122 is 'z'.
    Loop While ch < 48 Or ch > 57 And ch < 65 Or ch > 90 And ch < 97 Or ch > 122
    Mid(s, n, 1) = Chr(ch) 'bit more efficient than concatenation
Next

Debug.Print s
End Sub

1 个答案:

答案 0 :(得分:1)

在表单中添加一个文本框,并将s指定为文本框的Value ...

Debug.Print s
Me!txtDebug.Value = s

如果您要将s附加到文本框Value(而不是每次都替换Value),您可以将新的s值添加为新行...

Me!txtDebug.Value = Me!txtDebug.Value & vbCrLf & s