Type Mismatch

D

DS

I'm receiving a Type Mismatch error message #13 on this code;

Dim OpenSQL As Boolean
DoCmd.SetWarnings False
OpenSQL = "UPDATE tblNewDay SET tblNewDay.NewOpen = -1;"
DoCmd.RunSQL (OpenSQL)
DoCmd.SetWarnings True

The field at table level is set to Yes/No and True/False

Any input is appreciated.
Thanks
DS
 
K

Klatuu

You have your variable OpenSQL Dimmed as a Boolean varialbe and you are
trying to put a string value in it. Boolean variables are a one byte field
that can hold
only - 1 (True) or 0 (False).
You sould be Dimming it as a string

Just as a hint, For One Time shots, I don't bother with a variable, I just
use the sting. Also, the CurrentDb.Execute is much faster than RunSql and
you don't have to deal with the SetWarnings. I would code it this way:

CurrentDb.Execute("UPDATE tblNewDay SET tblNewDay.NewOpen = -1;"),
dbFailOnError

That would replace this:
Dim OpenSQL As Boolean
DoCmd.SetWarnings False
OpenSQL = "UPDATE tblNewDay SET tblNewDay.NewOpen = -1;"
DoCmd.RunSQL (OpenSQL)
DoCmd.SetWarnings True
 
C

Carl Rapson

DS said:
I'm receiving a Type Mismatch error message #13 on this code;

Dim OpenSQL As Boolean
DoCmd.SetWarnings False
OpenSQL = "UPDATE tblNewDay SET tblNewDay.NewOpen = -1;"
DoCmd.RunSQL (OpenSQL)
DoCmd.SetWarnings True

The field at table level is set to Yes/No and True/False

Any input is appreciated.
Thanks
DS

You defined OpenSQL as a Boolean data type, but you're trying to store a
string into it. Change the data type of OpenSQL to String.

Carl Rapson
 
B

bootybox via AccessMonster.com

Thanks, A very nice solution.
DS
You have your variable OpenSQL Dimmed as a Boolean varialbe and you are
trying to put a string value in it. Boolean variables are a one byte field
that can hold
only - 1 (True) or 0 (False).
You sould be Dimming it as a string

Just as a hint, For One Time shots, I don't bother with a variable, I just
use the sting. Also, the CurrentDb.Execute is much faster than RunSql and
you don't have to deal with the SetWarnings. I would code it this way:

CurrentDb.Execute("UPDATE tblNewDay SET tblNewDay.NewOpen = -1;"),
dbFailOnError

That would replace this:
Dim OpenSQL As Boolean
DoCmd.SetWarnings False
OpenSQL = "UPDATE tblNewDay SET tblNewDay.NewOpen = -1;"
DoCmd.RunSQL (OpenSQL)
DoCmd.SetWarnings True
I'm receiving a Type Mismatch error message #13 on this code;
[quoted text clipped - 9 lines]
Thanks
DS
 
B

bootybox via AccessMonster.com

Thanks, Carl
I understand that now.
DS

Carl said:
I'm receiving a Type Mismatch error message #13 on this code;
[quoted text clipped - 9 lines]
Thanks
DS

You defined OpenSQL as a Boolean data type, but you're trying to store a
string into it. Change the data type of OpenSQL to String.

Carl Rapson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top