Solved Help with Select Case (1 Viewer)

lookforsmt

Registered User.
Local time
Today, 11:34
Joined
Dec 26, 2011
Messages
672
HI! all

i am trying to use the below select statement to auto-fill the data if it meets the criteria.
User will select SOLid from combobox dropdown and IDSRef field will get auto-filled from unbound fields (txtPQR....etc)
Below is my statement
Code:
Private Sub SOLid_AfterUpdate()
Select Case Me![SOLid]
    Case 1
    Me.SOLid = "4101"
    Me.IDSRef = Me!Parent.txtPQR
    Case 2
    Me.SOLid = "1213"
    Me.IDSRef = Me!Parent.txtABC
    Case 3
    Me.SOLid = "1215"
    Me.IDSRef = Me!Parent.txtMAN
    Case 4
    Me.SOLid = "2512"
    Me.IDSRef = Me!Parent.txtXYZ
End Select
End Sub

thankyou
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:34
Joined
Sep 21, 2011
Messages
14,238
I have never seen a Case statement that sets the field/control being tested.? What is the point of that?

What exactly are you trying to do, as it is not clear to me?
 

lookforsmt

Registered User.
Local time
Today, 11:34
Joined
Dec 26, 2011
Messages
672
Let me explain with a db.
user will input data in txtPQR; txtABC; txtMAN and txtXYZ.
in the subform, user will select from SOLid dropdown matching in SOLref and it should pick the relevant txt.... data and populate in field "IDSref"

i was not able to find suitable select statement and tried to write one.
 

lookforsmt

Registered User.
Local time
Today, 11:34
Joined
Dec 26, 2011
Messages
672
added my db
 

Attachments

  • SelectTest_1.zip
    21.4 KB · Views: 76

isladogs

MVP / VIP
Local time
Today, 08:34
Joined
Jan 14, 2017
Messages
18,209
From your description, I think you need this (assuming SOLid is a number field.

Code:
Private Sub SOLid_AfterUpdate()
Select Case Me.SOLid
    Case 4101
    Me.IDSRef = Me!Parent.txtPQR
    Case 1213
    Me.IDSRef = Me!Parent.txtABC
    Case 1215
    Me.IDSRef = Me!Parent.txtMAN
    Case 2512
    Me.IDSRef = Me!Parent.txtXYZ
End Select
End Sub

If its a text field , restore the quotes

NOTE: I posted before you uploaded the dB and haven't looked at it.
 

lookforsmt

Registered User.
Local time
Today, 11:34
Joined
Dec 26, 2011
Messages
672
thanks Gasman, i have applied the code and changed the data type to Number and its working as expected.
But if i have keep the data type to Text, then how would i write the code.
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:34
Joined
Sep 21, 2011
Messages
14,238
Isaldogs gave you the answer, not me.?

I also had problems with the Me!Parent and used Me.Parent instead. ?
You would use the " " that you were using previously if any item was a string.
 

lookforsmt

Registered User.
Local time
Today, 11:34
Joined
Dec 26, 2011
Messages
672
oops! Sorry Isladogs, i missed that and thankyou for the solution you gave. I will close the thread as solved.

Thanks Gasman for the correction, i read that somewhere, strings are always in " ".

Thank you both. Have a nice day.
 
Last edited:

Users who are viewing this thread

Top Bottom