• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

Required Field in Datasheet View

Hello, I am a beginner when it comes to Access (probably giving me too much credit).  I have a subform in datasheet view with several fields.  One field is a combo box and the second is a text box.  I would like to make an entry in the text box required only when one of the selections from the combo box is selected and not required for any other selection.  Is this possible and if so how?  Thank you.
0
medic2069
Asked:
medic2069
  • 5
  • 4
1 Solution
 
mbizupCommented:
You could use VBA in the form's Before Update event:

Private Sub Form_BeforeUpdate(cancel as integer)
    If me.cboMyCombo = SomeSelection and nz(me.txtMyTextbox,"") = ""       then           '<--- checks for combo selection and blank/null textbox
           msgbox "You need to fill in the textbox for this selection in the combo"
           Cancel = True      '<----- cancels the update
   end if
end sub

You will need to substitute your own combo and textbox names for the above code to work.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Yes

Put this code in the BeforeUpdate event of your Form - which will look like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
   
    If IsNull(Me.Text1) AND Me.Combo1 = "YourRequiredValue" Then
          MsgBox "Please enter value in text box"
          Cancel = True              ' ** cancels the update
     End If

End Sub
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
I see you are gittin back at me for last night.  Why don't you go to be EARLY tonight, lol.

AND ... I wish YOU  ... would have got STUCK on the Q last night like did !!

mx
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
mbizupCommented:
Hee hee!   I figured you had it nailed, and unsubbed :-)
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
btw ... a P57 concurs ... it is TIME for the Neglected Q's to go :-)

mx
0
 
medic2069Author Commented:
Thank you for your help.  I tried mbizup's method and I kept getting an error.  Thanks again.  Have a great day!!!
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
You are welcome ...

So much for 'hee hee' ha ha ... but the two solutions were basically the same.  Hummmm.

mx

0
 
mbizupCommented:
Thanks for pointing that out, Joe :-)
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Maybe it was the non-string of
f me.cboMyCombo = SomeSelection

Some Selection ??

Sorry ...

Side note ... why don't the EE engineers fix the Upload ...>>>

See this Q ... near the bottom - upload issue

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_23132589.html

mx
0
 
mbizupCommented:
Hi Joe,

I don't think that is a new problem.  I noticed issues with posting just the quesiton ID some time ago and have always been using the full URL since then.  If this doesn't describe the problem as you are seeing it, send me an email (or use the Private Discussion thread... I'd like to see people start posting there.  I think that it is beneficial to all the experts subscribed to be aware of any issues with or on the site)

0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now