Update query to replace number with text (1 Viewer)

RyLane

Registered User.
Local time
Today, 14:42
Joined
Feb 4, 2014
Messages
60
Hi,

I've made a simple form to Login/Logout with radio buttons but the buttons only allow me to push a number as a value, in my case 1 or 2 for Login or Logout.

How would I make an update query to change those numbers to the equivalent text? Or is that not possible in the same field because that is 2 different data types?

Thanks,
 

bob fitz

AWF VIP
Local time
Today, 19:42
Joined
May 23, 2011
Messages
4,726
I don't know that this would work but perhaps in the "Update To" line in the update query you could use an IIF() function which would reference the radio buttons and return the appropriate value.
 

RyLane

Registered User.
Local time
Today, 14:42
Joined
Feb 4, 2014
Messages
60
Hi Bob,

I tried to do that with no luck. I have found some succes thought with the following SQL statement

UPDATE UpdatedActivity SET [Action] = "Logon"
WHERE [Activity] Like "*[1]*";

Here I've made another field called Action and am setting its value based on the Activity field number. I would like to inlude the logout option in the same statement but can't get that work yet.

I have zero coding experience and have just been playing around until something works. thought this would work, but no luck, just gives me zero's in the Action field.

UPDATE UpdatedActivity SET [Action] = "Login" & [Action] = "Logout"
WHERE ([Activity] Like "*[1]*") OR ([Activity] Like "*[2]*");

Worst comes to worst, I can just make 2 seperate Update Queries, one for Login, one for Logout.
 

bob fitz

AWF VIP
Local time
Today, 19:42
Joined
May 23, 2011
Messages
4,726
I managed to get the update to work using something like:
UPDATE UpdatedActivity SET Action= IIf([Forms]![LoginFormName]![OptButName]=-1,"Login","Log Out");
where LoginFormName is the name of the form and OptButName is the name of an Option Button. BTY, I used one option button and the the Caption property of its label to Logged In
EDIT
FYI, AFAIK Option buttons can only have a value of -1(selected) or 0(Not selected). Sound like you are using an Option group with two buttons.
 

RyLane

Registered User.
Local time
Today, 14:42
Joined
Feb 4, 2014
Messages
60
Hi Bob,

I was just doing the same thing myself, but you're right I am using the Option group with two radio buttons. So I have

UPDATE UpdatedActivity SET [Action] = IIF (Activity = 1,"Login", "Logout");

Works perfect. Thanks for the input about the IIF statement
 

Users who are viewing this thread

Top Bottom