Error in Code Mismatch

klynch0803

Registered User.
Local time
Today, 14:40
Joined
Jan 25, 2008
Messages
102
I have an error in this VB and it says Mismatch... Not sure what is wrong...

Can someone please help me find the error?

Code:
  Dim strsql As Boolean
    
   Debug.Print strsql = "SELECT * FROM qdatInventoryCheckupGather Diff " & _
                 "WHERE Diff = '' " & _
                 "ORDER BY Diff"
  
    DoCmd.RUNSQL strsql
    
    If Diff < 0 Then
    
    'test
    Diff = Converted
    
    Set rst = db.OpenRecordset("tdatINVENTORYUSAGE", dbOpenDynaset)
    
    
    With rst
        .AddNew
        !SaleDate = Now()
        !Item = Item ' Item from strsql query
        !Qty = Diff.Value ' Converted Value from strql sinve diff = converted above
        !Price = "0.00"
        !invShrtAdj = True
        .Update
   End With
    
    End If
    
    
    DoCmd.SetWarnings True
 
The errors start here:

Dim strsql As Boolean

You'd want String. They continue here:

Debug.Print strsql = "SELECT..."

You just want

strsql = "SELECT..."

What is Diff doing here?

strsql = "SELECT * FROM qdatInventoryCheckupGather Diff " & _

In that position it's a table alias. And this won't work, as you can only use RunSQL on an action query.

DoCmd.RUNSQL strsql

So you probably want to open a recordset. There's more, but I'm tired. Describe what you're trying to accomplish.
 
Describe what you're trying to accomplish.

First Thanks for taking the time to help out.

In the sql VB Code I'm trying to accomplish this in VB instead of an external Query....

Code:
SELECT [qdatInventoryCheckup Correct Inventory].InvDate, [qdatInventoryCheckup Correct Inventory].Item, [qdatInventoryCheckup Correct Inventory].systemBalance, [qdatInventoryCheckup Correct Inventory].ActualBalance, [qdatInventoryCheckup Correct Inventory].Diff, (Abs([diff])) AS Converted
FROM [qdatInventoryCheckup Correct Inventory];

Then run this

Code:
If diff < 0 Then
    
    diff = Converted
    
    Set rst = db.OpenRecordset("tdatINVENTORYUSAGE", dbOpenDynaset)
    
    
    With rst
        .AddNew
        !SaleDate = Now()
        !Item = Item ' Item from strsql query
        !Qty = diff.Value ' Converted Value from strql sinve diff = converted above
        !Price = "0.00"
        !invShrtAdj = True
        .Update
   End With
    
    ElseIf diff > 0 Then
    
    Set rst = db.OpenRecordset("tdatINVENTORYRec", dbOpenDynaset)
    
    
    With rst
        .AddNew
        !RcvdDate = Now()
        !Item = Item ' Item from strsql query
        !Qty = diff.Value
        !Cost = "0.00"
        !invShrtAdj = True
        .Update
   End With
    
    End If
 
In the sql VB Code I'm trying to accomplish this in VB instead of an external Query....

Code:
SELECT [qdatInventoryCheckup Correct Inventory].InvDate, [qdatInventoryCheckup Correct Inventory].Item, [qdatInventoryCheckup Correct Inventory].systemBalance, [qdatInventoryCheckup Correct Inventory].ActualBalance, [qdatInventoryCheckup Correct Inventory].Diff, (Abs([diff])) AS Converted
FROM [qdatInventoryCheckup Correct Inventory];
You can't do this Kurt. You can only write action queries in VB.
 
doco

i think its consensus not concensus

can we have a consensus on this?
 
what for? he knows what I mean. ;)

I meant just that. There is a difference between writing queries in modules, and writing SQL statements. They are two different entities in my view. You cannot write a SELECT query in Basic (and expect to do anything with it, in terms of actions). This was all said because of Kurt's particular situation and what he was trying to do inside of his own module.
 
You can write queries in VB.

e.g.

Code:
strSQL = "SELECT * FROM Blah WHERE something < something_else"

set querydef = currentdb.createquerydef("query_name", strSQL)

And you can also create temp queries as well

Code:
strSQL = "SELECT * FROM Blah WHERE something < something_else"

set querydef = currentdb.createquerydef("", strSQL)
 
I know that. It doesn't apply to this situation (I don't think).

To tell you the truth, correcting me on freakin' querydef syntax in Visual Basic is quite an insult.
 
Well don't write garbage like you can only write actions queries in VBA when you can write any sort of query you like using VBA.
 
Adam, while many of us knew what you meant, I think a rookie could easily be confused by "You can only write action queries in VB". In the OP's case, it's quite possible that opening a recordset on that SQL would be part of the solution, so that SQL being in the code might be appropriate (just misused as is).
 
Well, I've had enough of the idiots in this thread (why don't you do something useful, like work?).

Anyway, you must have said something stupid, because I rarely type something like this.

Coincidentally too, I know the OP. He's not a stranger to me.

(I'm thinking too...try to stay out of my threads now if you can, because I'm sure you don't want to read about garbage. You're much too intelligent for that. I don't want you to ruin your communication skills. Thanks).
 
If that little tirade is directed at me, I'd point out the the OP is not the only one reading the thread in the long run, so clarity is still important. In response to "try to stay out of my threads" I'll point out that you added to a thread I was already on, not vice-versa.
 
Its unanimous then, 'Consensus'. What is not clear should I be upset with Chergh now? :D
 

Users who are viewing this thread

Back
Top Bottom