If code defaulting to true (i think) (1 Viewer)

ljoekelsoey4

Registered User.
Local time
Today, 10:20
Joined
Mar 16, 2017
Messages
49
Hello. Creating a patient database. Patient ID is 10 numbers, with the 9th number being indicative of gender, even numbers are female. I've an unbound text box ("gender") using =Mid([ID],9,1) to pull out the relevant number, then using the following code to autopopulate another unbound text box, "gender_transfer". The text box bound to the table is called simply "Gender" and is coded to copy Text98 after ID update:

Private Sub ID_AfterUpdate()
If Me.gender_1 = "1" Or "3" Or "5" Or "7" Or "9" Then
Me.gender_transfer = "M"
Else
Me.gender_transfer = "F"
End If
Me.Gender = Me.Text98
End Sub

However after tabbing out of the ID field, "Text98" and by extension "Gender" default to male, regardless of the number in "Text98". Any idea why?

Thanks.
 

Minty

AWF VIP
Local time
Today, 10:20
Joined
Jul 26, 2013
Messages
10,380
You can't use the OR construct like that, you have to make the comparison each time, or better use a case statement.

So either
Code:
If Me.gender_1 = "1" Or Me.gender_1 = "3" Or Me.gender_1 = "5" Or Me.gender_1 = "7" Or Me.gender_1 = "9" Then...

Or
Code:
Select Case Me.Gender
Case 1,3,5,7,9
     Me.gender_transfer = "M"
Case Else
     Me.gender_transfer = "F"
End Select
 

ljoekelsoey4

Registered User.
Local time
Today, 10:20
Joined
Mar 16, 2017
Messages
49
Worked brilliantly, thanks a million
 

Users who are viewing this thread

Top Bottom