Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

prompt user to populate fields based on value in dropdown

Status
Not open for further replies.

ODBCERRORKING

Technical User
Mar 29, 2001
27
US
i have a field status code it is a dropdown list with certain codes called status_codes one of the list items is 61PM-Promised to pay i would like if the USER PICKS 61PM-Promised to pay THEN IT WILL MAKE THEM POPULATE OTHER FIELDS PROMISE _DATE,PROMISE AMOUNT,DUE_DATE
 
PFUNK

If you do an advanced search I'm sure you'll find some more examples.

Try something like this.
Code:
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo MY_ERROR
Dim ctl As Control
    For Each ctl In Me.Controls
    If Me.yourdropdownname.Value = "61PM-Promised to pay" Then
        If ctl.ControlType = acTextBox Then
        Select Case ctl.Name
          Case "PROMISE_DATE", "PROMISE_AMOUNT", "DUE_DATE"
            If IsNull(ctl) Then
                MsgBox ctl.Name & " is a required field, " & vbCr & _
                    "Please enter the required information to continue.", _
                    vbInformation, "Required Field"
           '     ctl.BackColor = 13303807    'Light Yellow
                ' Make sure you set the lost focus event
                ' for each textbox to set them back to default.
                    ' me.backcolor = vbwhite    'or  16777215
                ctl.SetFocus
                Cancel = True
                Exit Sub
            End If
        End Select
        End If
    End If
    Next ctl
Exit Sub
MY_ERROR:
MsgBox Err.Number & vbCr & vbCr & Err.Description
End Sub

Make sure the Select Case --- Case Field Names are in the same order as your forms Tab Order

Add something like this if you have a button that closes the form. Otherwise an error will occur.
Code:
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

    DoCmd.Close

Exit_cmdClose_Click:
    Exit Sub

Err_cmdClose_Click:
    'do nothing - User Required Data
    'Error 2501 - Close Action was canceled.
If Err.Number <> 2501 Then
    MsgBox Err.Number & Err.Description
End If
    Resume Exit_cmdClose_Click
    
End Sub

Hope this helps...

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Is it possible to make fields in your subform be require if a field in your main form has been changed as well?
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top