Progs
Progs

Reputation: 11

MS Access - VBA call variable

I am using VBA to develop a code which will automatically open an Access' form when a condition is met. Part of the Code is the following:

Private Sub Command10_Click()

DoCmd.RunCommand acCmdRefresh

DoCmd.OpenForm "NAME_OF_FORM", acNormal, "", "[NUMBER] = 500", , acHidden

Instead of setting "[NUMBER] = 500", I want to give a variable. Let's say:

Dim Test as String

Test = 500

When I try to run the following:

DoCmd.OpenForm "NAME_OF_FORM", acNormal, "", "[NUMBER] = Test", , acHidden

The command does not run, but it runs when I give the condition "[NUMBER] = 500".

Can you suggest anything?

Upvotes: 1

Views: 153

Answers (1)

asdev
asdev

Reputation: 943

You have to use a string concatenation. You combine two strings with the ampersand: &

Dim Test as String
Test = 500

DoCmd.OpenForm "NAME_OF_FORM", acNormal, "", "[NUMBER] =" & Test, , acHidden

Upvotes: 1

Related Questions