View Full Version : Referring to a VB variable in a query


MatMac
03-25-2008, 09:07 AM
Hi

I would like to add the value stored in a variable "yearpointer" into a table using an append query.

Probably something straightforward, but in the code below, "yearpointer" can't be found. (All other variables have been defined, although omitted here.)

Any idea what I am doing wrong? Thanks.


Private Sub processCosting()
Dim yearpointer As Integer

yearpointer = 1
Do While (yearpointer < acLast)
DoCmd.RunSQL "INSERT INTO costing ( projID, acYear, element, amount ) Values (001 , yearpointer, 'COST', 20)"
yearpointer = yearpointer + 1
Loop
End Sub

Alc
03-25-2008, 09:10 AM
Private Sub processCosting()
Dim yearpointer As Integer

yearpointer = 1
Do While (yearpointer < acLast)
DoCmd.RunSQL "INSERT INTO costing ( projID, acYear, element, amount ) Values (001 , " & yearpointer & ", 'COST', 20)"
yearpointer = yearpointer + 1
Loop
End Sub
Might do it.

MatMac
03-25-2008, 10:23 AM
That's got it - many thanks