0

So I am trying to ensure that all fields are filled on a form that i am creating however I am having some trouble with multiple if statements.

If Not IsEmpty(barcode) And Not IsEmpty(takenstock) And Not IsEmpty(staff) And Not IsEmpty(jobnumber) Then

    Sheet2.Cells(emptyrow, 1).Value = staff
    Sheet2.Cells(emptyrow, 2).Value = Product
    Sheet2.Cells(emptyrow, 3).Value = ProductCode
    Sheet2.Cells(emptyrow, 4).Value = takenstock
    Sheet2.Cells(emptyrow, 5).Value = jobnumber
    Sheet2.Cells(emptyrow, 6).Value = Mydate
    Sheet2.Cells(emptyrow, 7).Value = Mytime
    'removes stock from list of products
    Sheets("List of products").Range(findproduct).Value = selectproduct - takenstock
    'clears sheet
    Sheet1.Range("b1").Value = ""
    Sheet1.Range("b6").Value = ""
    Sheet1.Range("b5").Value = ""
    Sheet1.Range("b7").Value = ""
Else
    MsgBox "Please fill Barcode, stock to be taken,staff field and the job number" & vbNewLine & "Thank you", vbOKOnly, "Missing fields"

End If

This was my first attempt which didn't work, so i tried

If Not IsEmpty(barcode) And Not IsEmpty(takenstock) Then
    if Not IsEmpty(staff) And Not IsEmpty(jobnumber) Then

I have also tried removing the second Not's

Feels like I have tried everything but the code just isn't interested

Thank you in advance for your help

1 Answer 1

2

try

If (Not IsEmpty(barcode)) And (Not IsEmpty(takenstock)) And 
    (Not IsEmpty(staff)) And (Not IsEmpty(jobnumber)) Then

Always err on the side of more parenthesis...

Also, it depends on what Type barcode, takenstock, staff, and jobnumber are. I can't see your declarations.

If you declared them as Range and set them with something like

set barcode = Range("B7")

or something to that effect, your code should work fine. But if you declared them as String or Integer types and set them with

barcode = Range("B7").value

then your expression will always evaluate FALSE. isEmpty() is only for objects, not primitive types.

Sign up to request clarification or add additional context in comments.

6 Comments

When in doubt: Add more parenthesis
I have tried playing around using parenthesis, still no luck :(
In that case, what type are barcode, takenstock, staff, and jobnumber? Are they cell ranges, strings, integers,...?
barcode, staff and jobnumber are As String and takenstock As Integer, do you think this could be affecting it?
Integers are 0 (zero) as default. So I don't think that IsEmpty() will work very well on those.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.