Hello there!

I need your advice guys i got this error rrun-time error '13': type mismatch every time they reach the condition. Instead of msgbox its a run-time error. If i take the label16.caption = datediff its working fine.

Private Sub cmdnxt_Click()
Adodc1.Recordset.MoveNext
Label16.Caption = DateDiff("YYYY", Label15.Caption, Now)- type mismatch
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
MsgBox "End of File", vbInformation

End If
End Sub

Private Sub cmdprvs_Click()
Adodc1.Recordset.MovePrevious
Label16.Caption = DateDiff("YYYY", Label15.Caption, Now)- type mismatch
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
MsgBox "Begin of file", vbInformation
End If
End Sub

So what value is in Label15.Caption? If it's not a date, then you're going to have difficulties.

Also, please use "CODE" tags when you post code.

Then it should work fine. I could think of some ways for troubleshooting, but the most important right now is double checking if Label15 is indeed the correct label for the date field, and the values in the date field in your database.

@scudzzilla

if using this code: Label16.Caption = DateDiff("YYYY", Label15.Caption, Now) what is the correct entry in the my database. I have the entry in my database YYYY/dd/mm which bind in label15.

As long as the entry is a date or a string which resembles a date and includes a year, there should be no mismatch.

Hmm I just wanna check something. If you add an "On error resume next", does Label15 get filled with a date? Also, just for testing purposes, could you comment those datediff lines, and add a button which does the datediff line? Like:

Private Sub cmdnxt_Click()
Adodc1.Recordset.MoveNext
'Label16.Caption = DateDiff("YYYY", Label15.Caption, Now)- type mismatch
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
MsgBox "End of File", vbInformation

End If
End Sub

Private Sub cmdprvs_Click()
Adodc1.Recordset.MovePrevious
'Label16.Caption = DateDiff("YYYY", Label15.Caption, Now)- type mismatch
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
MsgBox "Begin of file", vbInformation
End If
End Sub

Private Sub Command1_Click()
Label16.Caption = DateDiff("YYYY", Label15.Caption, Now)
End Sub

Please see what happens after you click the new button, with a date already placed in Label15.

Edited 5 Years Ago by scudzilla: n/a

@scudzilla

Sir i add another command button but still run-time error is persist.

I am trying to make a program using VBA that will convert a word into code using a simple substitution cipher. I'm fairly new to VB but have some basic knowledge of it due to a course I took on it. Unfortunately this was not part of said course. The code I plan on using is taking the alphabet and converting it.

dog would be fqi if the shift amount was 2.
only lower case letters are included.
input in a input box.
input is text to be shifted and amount of shift.
output will be in excel in a 20 column by n row.
Any help would be appriciated.

This article has been dead for over six months. Start a new discussion instead.