Open a form with same ID, but as text string (1 Viewer)

bruceblack

Registered User.
Local time
Today, 14:32
Joined
Jun 30, 2017
Messages
119
Hi everyone. I'm stuck in a basement somewhere and need to fix this but cant find a solution all that quick.

I have the following code:

Code:
DoCmd.OpenForm "itemseditform", acNormal, , "[item_ID] = " & Me.item_ID

But the item_ID has been converted intentionally to a text string.

What is the right way to open a form linking to the ID when it's a text string?

Thanks for your help in advance!
 

JHB

Have been here a while
Local time
Today, 15:32
Joined
Jun 17, 2012
Messages
7,732
Add ' on both side.

Code:
DoCmd.OpenForm "itemseditform", acNormal, , "[item_ID] = [B][COLOR=red]'[/COLOR][/B]" & Me.item_ID [B][COLOR=Red]& "'"[/COLOR][/B]
 

bruceblack

Registered User.
Local time
Today, 14:32
Joined
Jun 30, 2017
Messages
119
Holy damn. Youre a life saver.

My brain must be sleeping somewhere else.

Thanks a ton!
 

bruceblack

Registered User.
Local time
Today, 14:32
Joined
Jun 30, 2017
Messages
119
Early in the morning by you? :D
Crapdoodle :D , yep early and no coffee

Now the form printouts dont work.

Code:
DoCmd.OpenReport "label1", acNormal, , "[item_ID] = '" & Me.item_ID & "'"

i applied the same method :S.....

But for reports is ANOTHER different way???
What is going on?
 
Last edited:

JHB

Have been here a while
Local time
Today, 15:32
Joined
Jun 17, 2012
Messages
7,732
Could it be that the report have the [item_ID] as a number? Then remove the '.
 

JHB

Have been here a while
Local time
Today, 15:32
Joined
Jun 17, 2012
Messages
7,732
..But the item_ID has been converted intentionally to a text string.
..
Converted it to text could cause many problem if you've queries and forms/reports already created.
 

June7

AWF VIP
Local time
Today, 06:32
Joined
Mar 9, 2014
Messages
5,423
Do you mean the field in table has been converted to a text data type?
 

Eugene-LS

Registered User.
Local time
Today, 17:32
Joined
Dec 7, 2018
Messages
481
Hi everyone. I'm stuck in a basement somewhere and need to fix this but cant find a solution all that quick.

I have the following code:

Code:
DoCmd.OpenForm "itemseditform", acNormal, , "[item_ID] = " & Me.item_ID
But the item_ID has been converted intentionally to a text string.

What is the right way to open a form linking to the ID when it's a text string?

Thanks for your help in advance!
...

Fourth argument of DoCmd.OpenForm instruction means WhereCondition in SQL format (without "WHERE ... "), so:

Code:
"[item_ID] = " & Me!item_ID     ' For numeric field
Or

Code:
"[item_ID] = '" & Me!item_ID  & "'"  ' For text field
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 14:32
Joined
Jan 14, 2017
Messages
18,186
Hi Eugene
Please don't post just to top up your numbers. It doesn't go down well.
You will soon reach the 'magic ten'
 

Users who are viewing this thread

Top Bottom