如何在vba模块中将组合框的值转换为字符串?

时间:2017-08-17 10:02:52

标签: vba ms-access combobox

我有一个example导出的表单根据查询执行xml。该查询是使用组合框的条件构建的。 组合框只有一个区域。 我想要的是,在vba模块中,使用组合框的条件命名de xml文件。

示例:组合框的值:03,Lucas,Roger,23。

file:myXML.Save" C:\ teste \ 03_Lucas_Roger_23.xml"

2 个答案:

答案 0 :(得分:0)

您可以使用以下表达式:

FileName = "C:\teste\" & Replace(Replace(Me!YourCombobox.Value, ",", "_"), " ", "") & "xml"

file: myXML.Save FileName

答案 1 :(得分:0)

您可以像这样连接值。 我为null添加了一个额外的测试,因为如果在一个或多个ComboBox上没有选择任何值,它将引发错误。

If IsNull(ComboBox1.Value) Or IsNull(ComboBox2.Value) Or IsNull(ComboBox3.Value) Or IsNull(ComboBox4.Value) Then
     MsgBox ("Not all values selected!")
Else
    Dim myFileName As String
    myFileName = "C:\teste\" & ComboBox1.Value & "_" & ComboBox2.Value & "_" & ComboBox3.Value & "_" & ComboBox4.Value & ".xml"
    myXML.Save myFileName
End If
相关问题