thechazm
VBA, VB.net, C#, Java
- Local time
- Today, 18:29
- Joined
- Mar 7, 2011
- Messages
- 515
Hey folks,
I am running into something that really is kicking my butt for some reason...
When I try to run a simple update query written in VBA I get no errors but the field that I am trying to update just gets a 0 instead of the appropriate ID that I am passing. Any help on this is appreciated but here is the VBA.
The funny thing is if I run the query itself it works by using a parameter query but when I try and run it like this all I get is 0's in the field that it's supposed to be updating.
The field [(SDSK) Charges Master].PID properties are as followed and is a linked table:
Type: Integer
Indexed: Yes (Duplicates Allowed)
A debug.print of the results of the query trying to be ran is the follows:
As you can see it is providing a number to be set to but instead it just fills it in with a 0.
Folks thanks in advance for any and all help with this. Thank you!
I am running into something that really is kicking my butt for some reason...
When I try to run a simple update query written in VBA I get no errors but the field that I am trying to update just gets a 0 instead of the appropriate ID that I am passing. Any help on this is appreciated but here is the VBA.
Code:
Function ExtractProjects()
On Error GoTo ErrHandler:
Dim db As Database, rs As DAO.Recordset, rs2 As DAO.Recordset, var() As Variant, i As Long, qdf As DAO.QueryDef, ii As Long
Set db = CurrentDb
Set rs = db.OpenRecordset("Select [ID], [SDSK] from [Project Name Ref] WHERE((([SDSK]) Is Not Null))", dbOpenSnapshot)
rs.MoveLast
rs.MoveFirst
ReDim var(rs.RecordCount, 2)
i = 0
Do While rs.EOF = False
var(i, 0) = rs("SDSK")
var(i, 1) = rs("ID")
i = i + 1
rs.MoveNext
Loop
rs.Close
For i = LBound(var) To UBound(var)
StatusLabel "Find Project Reference for ST and OT Charges. On Project: " & var(i, 0)
ii = var(i, 1)
db.Execute "UPDATE [(SDSK) Charges Master] SET [(SDSK) Charges Master].PID = " & ii & _
" WHERE ((([(SDSK) Charges Master].[IBB Date]) Between #" & GetChargesStart & "# And #" & GetChargesEnd & "#) AND " & _
"(([(SDSK) Charges Master].[Charge Num]) Like '*" & var(i, 0) & "*' And ([(SDSK) Charges Master].[Charge Num]) Is Not Null));", dbFailOnError
Next i
StatusLabel "Completed!"
Set qdf = Nothing
Set db = Nothing
Exit Function
ErrHandler:
If Err.Number = 3052 Then
StatusLabel "Clearing Buffer..."
Err.Clear
Resume
Else
MsgBox Err.Number & " " & Err.Description
End If
Set qdf = Nothing
Set db = Nothing
End Function
The funny thing is if I run the query itself it works by using a parameter query but when I try and run it like this all I get is 0's in the field that it's supposed to be updating.
The field [(SDSK) Charges Master].PID properties are as followed and is a linked table:
Type: Integer
Indexed: Yes (Duplicates Allowed)
A debug.print of the results of the query trying to be ran is the follows:
Code:
UPDATE [(SDSK) Charges Master] SET [(SDSK) Charges Master].PID = 1 WHERE ((([(SDSK) Charges Master].[IBB Date]) Between #10/24/2014# And #11/19/2014#) AND (([(SDSK) Charges Master].[Charge Num]) Like '*BAA*' And ([(SDSK) Charges Master].[Charge Num]) Is Not Null));
As you can see it is providing a number to be set to but instead it just fills it in with a 0.
Folks thanks in advance for any and all help with this. Thank you!
Last edited: