Forum Discussion

markarel's avatar
markarel
Brass Contributor
Mar 23, 2022
Solved

Set default value in ComboBox from a SQL query

Hello everybody!   I'm creating a DB and I have a problem with a form. In one of the ComboBoxes I use, I would like to put as default value the result of a SQL query, the problem is that it does no...
  • George_Hepworth's avatar
    George_Hepworth
    Mar 23, 2022

    George_Hepworth 

     

    Okay, then, I was not treating the default as a string, which it needs to be.

    Try this, using DLookup and the string delimiters.

     


    Private Sub Form_Load()

     

        Dim strUserName As String

        strUserName = DLookup("name", "users", "username = " & fncUser() )

        Me.YourComboBoxNameGoesHere.DefaultValue = """" & strUserName & """"

    End Sub

Resources