简体   繁体   中英

How to allow one single entry in a multi field entry form with VBA

I have made a data entry form which creates a row in another sheet from those data.

I then have to make another entry form where it is possible only to type in one of the specific data entries from the entry form before. That should then find all rows containing this specific entry and move these rows to a third sheet.

How do I specify that only one single entry is allowed in the entry form?

I thought about using:

If Not IsEmpty(Me.Textbox1.Value) then
   MsgBox "Only one entry is allowed"
End If

But of course this just locks the specific input box.

Thanks!

Standard checks during a commandbutton_click event, which is above the rest of the scripting that would happen where this isn't true, would be a for each loop to check the controls in the form. you can use a dummy variable to check how many textbox controls have values, similar to:

for each ctrl in me.controls
    if typename(ctrl) = "textbox" then 'important
        if ctrl.value <> "" then i = i+1
    end if
next ctrl
if i > 1 then 
    msgbox "don't be dumb"
    exit sub
end if
'insert code that runs when only 1 textbox is used

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