Search code examples
excelvbauserform

Using userform data, how can I transfer only the first five digits of a field to my database field (crossposted)


I am attempting to move code to a database from my userform and all of my data is transferring perfect including this field, however, I need to add the limitation of only moving the first 5 characters of this field. I believe using 'Left(Cell.value, 5)' in my code should work, but I can't seem to figure out where to insert it. I do not need to worry about anything being inserted inappropriately as the field is a drop-down combo box with the options they can use. My line code is below and it works to move the entire field to my database but as I said, I need to limit transfer to only the first five digits. Any help would be greatly appreciated!

Sheets("Travel Expense Codes").Range("DataStartCodes").Offset(CodesTargetRow, 11).value = cmbOtherExpenseCode

Solution

  • Your thinking is correct. You can use LEFT() function with combobox like this Left(cmbOtherExpenseCode,5). Check below code.

    Sheets("Travel Expense Codes").Range("DataStartCodes").Offset(CodesTargetRow, 11).value = Left(cmbOtherExpenseCode,5)