Hi, I am new to VBA. Trying to enter data into a table names Signals. The command I'm using is
DoCmd.RunSQL "INSERT INTO signals ([date], sw, c )VALUES (s_date, buyflag, rut);"
It displays a parameter box to enter a value rather than using the variables I have defined.
I'm stumped.
Public Sub VXO()
'Set up the connection, name it cnn1 .
Dim cnn1 As ADODB.Connection
Set cnn1 = New ADODB.Connection
'Declare record set
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
'Define variables
Dim diff As Single, BuyFlag As Integer
Dim ma19 As Single, ysumix As Single, ysumix49 As Single, yvxo As Single
Dim ma39 As Single, yd2dma As Single
Dim madiff As Single, sumix49ma As Single, sumix2ma As Single, d2dma As Single
Dim total As Single, ysum2dma As Single
Dim calc1 As Single, s_date As Date
Dim calc2 As Single, rut As Single
Dim net As Single
rst.LockType = adLockOptimistic
rst.Open "select * from otc", CurrentProject.Connection
BuyFlag = 0
Do Until rst.EOF
'Calculate moving averages on Summation Ix
sumix49ma = (rst.Fields("sumix") * 0.04) + (sumix49ma * 0.96)
sumix2ma = (rst.Fields("SUMIX") * 0.67) + (sumix2ma * 0.33)
d2dma = (rst.Fields("SUMIX") * 0.5) + (d2dma * 0.5)
rut = rst.Fields("c")
If BuyFlag = 0 Then
GoTo BuyRtn
Else
GoTo SellRtn
End If
BuyRtn:
'Buy Rule 1
If ysumix > ysumix49 _
And yvxo < 38 _
And ysumix > 390 And ysumix < 870 Then _
BuyFlag = 1
'Buy Rule 2
If BuyFlag = 0 Then
If ysumix < 0 Then
BuyFlag = 1
End If
End If
GoTo GetNextRec
SellRtn:
If ysumix < yd2dma _
And ysumix >= -48 And ysumix <= 882 Then _
BuyFlag = 0
GoTo GetNextRec
GetNextRec:
ysumix = rst.Fields("sumix")
ysumix49 = sumix49ma
ysum2dma = sumix2ma
yd2dma = d2dma
' yvxo = rst.Fields("VXO")
s_date = rst.Fields("date")
Debug.Print s_date, BuyFlag
DoCmd.RunSQL "INSERT INTO signals ([date], sw, c )VALUES (s_date, buyflag, rut);"
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
DoCmd.RunSQL "INSERT INTO signals ([date], sw, c )VALUES (s_date, buyflag, rut);"
It displays a parameter box to enter a value rather than using the variables I have defined.
I'm stumped.
Public Sub VXO()
'Set up the connection, name it cnn1 .
Dim cnn1 As ADODB.Connection
Set cnn1 = New ADODB.Connection
'Declare record set
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
'Define variables
Dim diff As Single, BuyFlag As Integer
Dim ma19 As Single, ysumix As Single, ysumix49 As Single, yvxo As Single
Dim ma39 As Single, yd2dma As Single
Dim madiff As Single, sumix49ma As Single, sumix2ma As Single, d2dma As Single
Dim total As Single, ysum2dma As Single
Dim calc1 As Single, s_date As Date
Dim calc2 As Single, rut As Single
Dim net As Single
rst.LockType = adLockOptimistic
rst.Open "select * from otc", CurrentProject.Connection
BuyFlag = 0
Do Until rst.EOF
'Calculate moving averages on Summation Ix
sumix49ma = (rst.Fields("sumix") * 0.04) + (sumix49ma * 0.96)
sumix2ma = (rst.Fields("SUMIX") * 0.67) + (sumix2ma * 0.33)
d2dma = (rst.Fields("SUMIX") * 0.5) + (d2dma * 0.5)
rut = rst.Fields("c")
If BuyFlag = 0 Then
GoTo BuyRtn
Else
GoTo SellRtn
End If
BuyRtn:
'Buy Rule 1
If ysumix > ysumix49 _
And yvxo < 38 _
And ysumix > 390 And ysumix < 870 Then _
BuyFlag = 1
'Buy Rule 2
If BuyFlag = 0 Then
If ysumix < 0 Then
BuyFlag = 1
End If
End If
GoTo GetNextRec
SellRtn:
If ysumix < yd2dma _
And ysumix >= -48 And ysumix <= 882 Then _
BuyFlag = 0
GoTo GetNextRec
GetNextRec:
ysumix = rst.Fields("sumix")
ysumix49 = sumix49ma
ysum2dma = sumix2ma
yd2dma = d2dma
' yvxo = rst.Fields("VXO")
s_date = rst.Fields("date")
Debug.Print s_date, BuyFlag
DoCmd.RunSQL "INSERT INTO signals ([date], sw, c )VALUES (s_date, buyflag, rut);"
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub