samonwalkabout
Registered User.
- Local time
- Today, 13:01
- Joined
- Mar 14, 2003
- Messages
- 185
SQL
I have his code running in the database no worries, but I want to Change it so it takes the "adjustment" value from a qry not from the table "newstock" As im having to update this before i run the code and it causing trouble. The code reads...
Dim rst As Recordset
Dim dt As Date
Dim lngAmnt As Long
Dim db As DAO.Database
Dim strSQL As String, strSQL2 As String
Dim rstProChem As Recordset
Dim intChemicalID As Integer, intProcessID As Integer
Set db = CurrentDb
intProcessID = [Forms]![update]![cmbProcess]
strSQL2 = "SELECT prochem.[Chemical ID], Process.[Process ID] " _
& "FROM Process INNER JOIN prochem ON Process.[Process ID] = prochem.[Process ID] " _
& "GROUP BY prochem.[Chemical ID], Process.[Process ID] " _
& "HAVING (((Process.[Process ID])=" & intProcessID & "));"
Set rstProChem = db.OpenRecordset(strSQL2, dbOpenDynaset)
With rstProChem
.MoveFirst
Do Until .EOF
intChemicalID = ![Chemical ID]
strSQL = "SELECT [Chemical ID], [Week End Date],Startamt, endamt, adjustment " _
& "FROM newstock " _
& "WHERE [Chemical ID]=" & intChemicalID & ";"
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
lngAmnt = rst!Startamt
With rst
.MoveFirst
Do Until .EOF
.Edit
!Startamt = lngAmnt
!endamt = !Startamt + !adjustment
'!Adjustment = !Adjustment
.update
lngAmnt = !endamt
.MoveNext
Loop
End With
.MoveNext
Loop
End With
End Sub
I have a qry called "Adjustment" with [Chemical ID], [Week End Date] and [Adjustment] but cant seem to get the code right to slot it in. I think its my poor grasp of sql joins. Anyone good at em??
I have his code running in the database no worries, but I want to Change it so it takes the "adjustment" value from a qry not from the table "newstock" As im having to update this before i run the code and it causing trouble. The code reads...
Dim rst As Recordset
Dim dt As Date
Dim lngAmnt As Long
Dim db As DAO.Database
Dim strSQL As String, strSQL2 As String
Dim rstProChem As Recordset
Dim intChemicalID As Integer, intProcessID As Integer
Set db = CurrentDb
intProcessID = [Forms]![update]![cmbProcess]
strSQL2 = "SELECT prochem.[Chemical ID], Process.[Process ID] " _
& "FROM Process INNER JOIN prochem ON Process.[Process ID] = prochem.[Process ID] " _
& "GROUP BY prochem.[Chemical ID], Process.[Process ID] " _
& "HAVING (((Process.[Process ID])=" & intProcessID & "));"
Set rstProChem = db.OpenRecordset(strSQL2, dbOpenDynaset)
With rstProChem
.MoveFirst
Do Until .EOF
intChemicalID = ![Chemical ID]
strSQL = "SELECT [Chemical ID], [Week End Date],Startamt, endamt, adjustment " _
& "FROM newstock " _
& "WHERE [Chemical ID]=" & intChemicalID & ";"
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
lngAmnt = rst!Startamt
With rst
.MoveFirst
Do Until .EOF
.Edit
!Startamt = lngAmnt
!endamt = !Startamt + !adjustment
'!Adjustment = !Adjustment
.update
lngAmnt = !endamt
.MoveNext
Loop
End With
.MoveNext
Loop
End With
End Sub
I have a qry called "Adjustment" with [Chemical ID], [Week End Date] and [Adjustment] but cant seem to get the code right to slot it in. I think its my poor grasp of sql joins. Anyone good at em??