Using MS Access/if else if help

Advertisement


Question
Plz Tell error to handle this action

Private Sub SUBJECTS_Enter()
If MEDIUM.Text = "URDU" Then
SUBJECTS.Text = "ENG,URDU,IT,MATH"
ElseIf MEDIUM.Text = "SINDHI" Then
SUBJECTS.Text = "ENG,SINDHI,IT,MATH"
Else
SUBJECTS.Text = "ENG,SINDH,IK,MATH"
End If
End Sub

Answer
I'm not clear what you want. But if I were coding thia I would use:

Private Sub SUBJECTS_Enter()
SELECT CASE Me.MEDIUM

   Case "URDU"
       Me.SUBJECTS = "ENG,URDU,IT,MATH"

   Case "SINDHI"
       Me.SUBJECTS = "ENG,SINDHI,IT,MATH"

   Case Else
       Me.SUBJECTS = "ENG,SINDH,IK,MATH"
End Select
End Sub

I almost never use the Text property of a control. The Text property is the currently displayed  text in a text control or combobox. I generally use the Value property, which is the default so it doesn't have to explicitly listed.

Also I would not use the On Enter event. With your code the Subjects control needs to have focus. With mine it doesn't so I would use the After Update event of the Medium control.

And one more thing. It's not clear what you are doing here, but I would think Subjects should be a child table, not a field in your main table. So that you can list each subject as a separate record.

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Website: http://www.diamondassoc.com
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scottgem

Expertise

I can answer almost all types of questions relating to Microsoft Access usage and application design. My strengths are database and interface design.

Experience

I've been designing databases for over 25 years working with dBase, FoxPro, Approach and Access.

Organizations
Author of Microsoft Office Access 2007 VBA
Techncial Editor for Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports & Queries From Que Publishing

Education/Credentials
Brooklyn College BA

©2016 About.com. All rights reserved.