A
AccessAddict
Hello All,
Hoping someone can help me, I am in the learning stages of SQL and VBA.
I've been using Access for quite some time now (since 1998) and have limited
knowledge of SQL/VBA. Thus, HELP.
I created an unbound form, full of text boxes (named txtPO1_1/2/2005,
txtPO1_1/30/2005, etc) across the form and the boxes going down which
increment according to the row (Example for first column/first row =
txtPO1_1/2/2005, first column/second row = txtPO2_1/2/2005, first
column/third row = txtPO3_1/2/2005, etc.). The first column increments its
name (down the rows) accordingly - txtITEM_1, txtITEM_2, etc. A combo box
allows the user to choose a group and the form fills with information from
the "many-side" table for each of the items in the group specified. Then a
button clears the form for the next group.
I now want to update this information (which I want the user to be able to
change) to the "many-side" table.
I am running into a problem with either the SQL or VBA syntax or my
knowledge of it. I'm attaching my code, perhaps someone can help me figure
this out?
The error states "syntax error (missing operator) in query expression
'Forms!Group Test Update Matrix 1.Me"txtPO1_1/2/2005" > 0'."
I am trying to get the update to find the textbox named txtPO1_1/2/2005 and
update (according to the textbox it finds - in this case, #1/2/2005#) to the
field [Post Off Start Date] in the table called [N POST OFF TABLE test] and
to update the textbox contents (value) the field [Post Off Price] in the same
table.
The problem is in the "DoCmd.RunSQL" line, nested in the middle of the
innermost "Do Until" line.
Thank you in advance (for even reading all of this - I know its long).
Private Sub UpdateGroup_Click()
On Error GoTo Err_UpdateGroup_Click
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim intITEM As Integer
Dim hldITEM As String
Dim intGroup As Integer
Dim hldGroup As String
Dim hldPOST As String
Dim intPO As Integer
Dim cboGroup As String
cboGroup = Me.cboSUPSUBFL.Value
strSQL = "SELECT [SUPSUBFL],[Post Off Start Date],[Item Description],[Post
Off Price],[N POST OFF TABLE test].[Item #] FROM [N ITEM PRICING TABLE
test]INNER JOIN[N Post Off Table test] ON [N item Pricing Table test].[Item
#]=[N POST OFF TABLE test].[Item #]where [N ITEM PRICING TABLE
test].[SUPSUBFL] = '" & cboGroup & "' ORDER BY [SUPSUBFL],[N Post Off Table
test].[Item #],[Post Off Start Date]"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
rs.MoveFirst
With rs
intGroup = 0
intITEM = 0
intPO = 0
hldGroup = cboGroup
'hldGroup = .Fields("SUPSUBFL")
hldITEM = .Fields("[Item #]")
Do Until hldGroup <> .Fields("SUPSUBFL") Or .EOF
Me("txtGroup") = hldGroup
intGroup = intGroup + 1
intITEM = intITEM + 1
Do Until .EOF Or hldGroup <> .Fields("SUPSUBFL")
hldITEM = .Fields("[Item #]")
Me("txtITEM" & intITEM) = hldITEM & " / " &
..Fields("[item description]")
intPO = intPO + 1
Do Until hldITEM <> .Fields("Item #") Or .EOF
If (.Fields("[Post Off Start Date]") < #6/5/2005#)
Then
hldPOST = Str$(.Fields("[Post Off Start Date]"))
Me("txtPO" & intPO & "_" & hldPOST) = .Fields("[Post
Off Price]")
DoCmd.RunSQL ("UPDATE [N Post Off Table test] INNER JOIN [N
ITEM PRICING TABLE test] on [N ITEM PRICING TABLE test].[Item #] = [N POST
OFF TABLE test].[Item #] SET [Post Off Start Date] = #1/2/2005# WHERE
Forms!Group Test Update Matrix 1.Me""txtPO1_1" & Chr(47) & "2" & Chr(47) &
"2005"" > 0 ")
End If
.MoveNext
Loop
intITEM = intITEM + 1
Loop
Loop
.Close
End With
Set rs = Nothing
Set db = Nothing
Exit_UpdateGroup_Click:
Exit Sub
Err_UpdateGroup_Click:
MsgBox Err.Description
Resume Exit_UpdateGroup_Click
End Sub
Hoping someone can help me, I am in the learning stages of SQL and VBA.
I've been using Access for quite some time now (since 1998) and have limited
knowledge of SQL/VBA. Thus, HELP.
I created an unbound form, full of text boxes (named txtPO1_1/2/2005,
txtPO1_1/30/2005, etc) across the form and the boxes going down which
increment according to the row (Example for first column/first row =
txtPO1_1/2/2005, first column/second row = txtPO2_1/2/2005, first
column/third row = txtPO3_1/2/2005, etc.). The first column increments its
name (down the rows) accordingly - txtITEM_1, txtITEM_2, etc. A combo box
allows the user to choose a group and the form fills with information from
the "many-side" table for each of the items in the group specified. Then a
button clears the form for the next group.
I now want to update this information (which I want the user to be able to
change) to the "many-side" table.
I am running into a problem with either the SQL or VBA syntax or my
knowledge of it. I'm attaching my code, perhaps someone can help me figure
this out?
The error states "syntax error (missing operator) in query expression
'Forms!Group Test Update Matrix 1.Me"txtPO1_1/2/2005" > 0'."
I am trying to get the update to find the textbox named txtPO1_1/2/2005 and
update (according to the textbox it finds - in this case, #1/2/2005#) to the
field [Post Off Start Date] in the table called [N POST OFF TABLE test] and
to update the textbox contents (value) the field [Post Off Price] in the same
table.
The problem is in the "DoCmd.RunSQL" line, nested in the middle of the
innermost "Do Until" line.
Thank you in advance (for even reading all of this - I know its long).
Private Sub UpdateGroup_Click()
On Error GoTo Err_UpdateGroup_Click
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim intITEM As Integer
Dim hldITEM As String
Dim intGroup As Integer
Dim hldGroup As String
Dim hldPOST As String
Dim intPO As Integer
Dim cboGroup As String
cboGroup = Me.cboSUPSUBFL.Value
strSQL = "SELECT [SUPSUBFL],[Post Off Start Date],[Item Description],[Post
Off Price],[N POST OFF TABLE test].[Item #] FROM [N ITEM PRICING TABLE
test]INNER JOIN[N Post Off Table test] ON [N item Pricing Table test].[Item
#]=[N POST OFF TABLE test].[Item #]where [N ITEM PRICING TABLE
test].[SUPSUBFL] = '" & cboGroup & "' ORDER BY [SUPSUBFL],[N Post Off Table
test].[Item #],[Post Off Start Date]"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
rs.MoveFirst
With rs
intGroup = 0
intITEM = 0
intPO = 0
hldGroup = cboGroup
'hldGroup = .Fields("SUPSUBFL")
hldITEM = .Fields("[Item #]")
Do Until hldGroup <> .Fields("SUPSUBFL") Or .EOF
Me("txtGroup") = hldGroup
intGroup = intGroup + 1
intITEM = intITEM + 1
Do Until .EOF Or hldGroup <> .Fields("SUPSUBFL")
hldITEM = .Fields("[Item #]")
Me("txtITEM" & intITEM) = hldITEM & " / " &
..Fields("[item description]")
intPO = intPO + 1
Do Until hldITEM <> .Fields("Item #") Or .EOF
If (.Fields("[Post Off Start Date]") < #6/5/2005#)
Then
hldPOST = Str$(.Fields("[Post Off Start Date]"))
Me("txtPO" & intPO & "_" & hldPOST) = .Fields("[Post
Off Price]")
DoCmd.RunSQL ("UPDATE [N Post Off Table test] INNER JOIN [N
ITEM PRICING TABLE test] on [N ITEM PRICING TABLE test].[Item #] = [N POST
OFF TABLE test].[Item #] SET [Post Off Start Date] = #1/2/2005# WHERE
Forms!Group Test Update Matrix 1.Me""txtPO1_1" & Chr(47) & "2" & Chr(47) &
"2005"" > 0 ")
End If
.MoveNext
Loop
intITEM = intITEM + 1
Loop
Loop
.Close
End With
Set rs = Nothing
Set db = Nothing
Exit_UpdateGroup_Click:
Exit Sub
Err_UpdateGroup_Click:
MsgBox Err.Description
Resume Exit_UpdateGroup_Click
End Sub