WhereCondition in ExportXML

harkirat777

New member
Local time
Today, 09:18
Joined
Jul 23, 2013
Messages
4
Hi,
I was writing a code for a form to export the table (Intro_1) for a field which is specified in a textbox(selectID1), then clicking on a button to export to XML (Exported_XML.xml), using the WhereCondition:

Code:
Public Sub Command9_Click()
 
    Application.ExportXML ObjectType:=acExportTable, _
    DataSource:="Intro_1", _
    DataTarget:="E:\VBAx\Exported_XML.xml", _
    WhereCondition:="ID='Me.selectID1'"
 
End Sub

The code does not export anything. :confused:

However, if I hardcode the ID value in WhereCondition, i.e without picking up the value from the textbox:
Code:
WhereCondition:="ID='5'"
it works absolutely fine. :banghead:

Can anyone help me how to use the value entered in the textbox in WhereCondition please.

I have done a lot of head scratching, cannot find out why. I used another textbox to capture the value of 'Me.selectID1' which is 5, it is receiving the right value, still does not work.
 
Hello harkirat777, Welcome to AWF.. :)

You have not seemed to concatenated the values.. Try..
Code:
WhereCondition:="ID='[COLOR=Red][B]" &[/B][/COLOR] Me.selectID1 [COLOR=Red][B]& "'[/B][/COLOR]"
 
Hello harkirat777, Welcome to AWF.. :)

You have not seemed to concatenated the values.. Try..
Code:
WhereCondition:="ID='[COLOR=red][B]" &[/B][/COLOR] Me.selectID1 [COLOR=red][B]& "'[/B][/COLOR]"

Thank you very much Paul for your superfast reply.
Firstly, I worked perfectly, thank you. :D

If you please don't mind could you explain me why did we use " and &? I am sorry im very new to vba access, just started 2 days back.
Cheerio
 
Glad you got it working.. Well if you need to use a variable along with a hardcoded String.. Then you Concatenate them.. So it will take the value from the variable not the actual string.. You use double quotes and ampersand symbol to get it.. if it is a String you enclose them between single quotes.. Number no enclosure.. Dates with the hash symbol..
Code:
' For Numbers:
WhereCondition:="ID=" & Me.selectID1
' For Strings
WhereCondition:="ID='" & Me.selectID1 & "'"
' For Dates
WhereCondition:="ID=#" & Me.selectID1 & "#"
Hope that helps.. :)
 
Glad you got it working.. Well if you need to use a variable along with a hardcoded String.. Then you Concatenate them.. So it will take the value from the variable not the actual string.. You use double quotes and ampersand symbol to get it.. if it is a String you enclose them between single quotes.. Number no enclosure.. Dates with the hash symbol..
Code:
' For Numbers:
WhereCondition:="ID=" & Me.selectID1
' For Strings
WhereCondition:="ID='" & Me.selectID1 & "'"
' For Dates
WhereCondition:="ID=#" & Me.selectID1 & "#"
Hope that helps.. :)

Thanks a million, that was a lot of help!
 
Most welcome and Good luck in your new job.. :)
 
Hi,

I am using exact function however I get this error;
"Run - time error '31532'
Microsoft Access was unable to export the data".

Any idea why is this happening?

Thank you in advance!
 
It is very hard to explain why this happens, if you could start a new thread and explain your problem with the code you have me/someone might be able to look over it.
 
Hi pr2-eugin,

I made a new thread with this title: Microsoft Access (2010) was unable to export data using export query for xml
 

Users who are viewing this thread

Back
Top Bottom