简体   繁体   中英

Placing Label Over Combo-box in Ms-Access

Background:

I am trying to place a label in Ms-Access that is being used as a button over a combo box. The user will select from the combo-box list and if they want to erase their selection they can click on the label to clear the selection.

Question:

Is it possible to get the label to show above the combo? It seems like the label is being sent behind the combo even though I specifically send it to the from etc...

Instead of creating the overlaying label to clear the selection, I would create an actual button. You will stack the button and the combo box on top of eachother in design mode, but set the button visibility to "No" in the format properties. Let's say you call the combo box "cmbSelect" and the clear button "cmdClear", use the following to show the button after the combo box is selected:

Private Sub cmbSelect_AfterUpdate

Me.cmdClear.Visible = True

End Sub

The following code will then clear the data from your table after the button is clicked:

Private Sub cmdClear_Click()


DoCmd.SetWarnings False


'Deletes record from your table
Dim Delete As String
Delete = "DELETE * FROM [TableName] WHERE (([TableName].KeyField)='" & KeyField & "')"
DoCmd.RunSQL Delete

DoCmd.SetWarnings True

End Sub

You could also have the form requery by running a requery on each field instead of using the delete string. Then you could build code for the button "after update" that makes the button invisible again and allows you to select a new entry from the combo box. There's a lot of possibility, but this should get you started. Let me know if you need any more explanation or help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM