1

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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.