Default Values (2 Viewers)

sheepchild

New member
Local time
Today, 12:51
Joined
Feb 23, 2024
Messages
3
I have a random issue which i cant work out

i have a look up
Code:
=DLookUp("MinFaculty","tbl_CourseNames","ID=" & [EventTitleCombo])
which works in a text box under the control source and show the correct value i want

but i want this in the default value with the control source [MinNoFaculty]

but when i do it just shows blank???

what am i missing? any help would be great!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:51
Joined
May 7, 2009
Messages
19,244
the controlSource of your Textbox is an Expression.
Remove it and use the Current event and AfterUpdate event of your Combobox of your Form:


Private sub Form_Current()
If Me![EventTitleCombo].ListIndex < 0 Then
Me.TheTextbox = [MinNoFaculty]
Else
Me.TheTextbox = DLookUp("MinFaculty","tbl_CourseNames","ID=" & [EventTitleCombo])
End If
End Sub

Private Sub EventTitleCombo_AfterUpdate()
Call Form_Current
End Sub
 

sheepchild

New member
Local time
Today, 12:51
Joined
Feb 23, 2024
Messages
3
the controlSource of your Textbox is an Expression.
Remove it and use the Current event and AfterUpdate event of your Combobox of your Form:


Private sub Form_Current()
If Me![EventTitleCombo].ListIndex < 0 Then
Me.TheTextbox = [MinNoFaculty]
Else
Me.TheTextbox = DLookUp("MinFaculty","tbl_CourseNames","ID=" & [EventTitleCombo])
End If
End Sub

Private Sub EventTitleCombo_AfterUpdate()
Call Form_Current
End Sub
Oooooh thank you. if i wanted extra defaults such as maxCandidates (same look up how would this work as it all set via the combo box as apose each text box its being posted too?

tried a few things but keep getting errors

thank you again massive step forward for me
 

sheepchild

New member
Local time
Today, 12:51
Joined
Feb 23, 2024
Messages
3
Oooooh thank you. if i wanted extra defaults such as maxCandidates (same look up how would this work as it all set via the combo box as apose each text box its being posted too?

tried a few things but keep getting errors

thank you again massive step forward for me
Think i have managed it!


Code:
Private Sub Form_Current()
    If Me![EventTitleCombo].ListIndex < 0 Then
        Me.MinNoFaculty = [MinNoFaculty]
    Else
        Me.MinNoFaculty = DLookup("MinFaculty", "tbl_CourseNames", "ID=" & [EventTitleCombo])
        Me.MaxNoDelegates = DLookup("MaxCandidates", "tbl_CourseNames", "ID=" & [EventTitleCombo])

    End If
End Sub

i was putting in the top bit twice at the top thinking that i would need to specify each text box its was filling out.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:51
Joined
Oct 29, 2018
Messages
21,473
Hi. Welcome to AWF!

Just curious, have you tried using DLookup() in the Default Value property of each Textbox?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:51
Joined
Feb 19, 2002
Messages
43,275
Do NOT use the form's Current event to dirty the record. You will be overwriting existing records AND you will be dirting every record the use navigates to whether he wants to enter a record or not.

The correct event to use is the BeforeInsert event. That event runs ONLY once and ONLY for new records. AND it runs AFTER the user has dirtied the record so you know that he is intending to add a new record.

If you want to set the default and let access populate the control, then set the default value for the control in the form's Open event.

Events are not random nor are they interchangeable. Events have a purpose and it is important to understand what causes them to fire so you know which events your code needs to go in to be effective.
 

Users who are viewing this thread

Top Bottom