PLEASE. update access from module

M

michelle

Since noone has answered my question I'll try again, I bet many of you
see's my misstake.
PLEASE, help me.

I have written a module which is calling from a form.

---------------
Function RunTheChangeBox()


Const myPicture = "SELECT DISTINCT
[Photos].[boxId],[Photos].[magasinId]," & _
" [Photos].[pictureId], [Photos].[magasineName],[Photos].[date],
[Photos].[rowId] " & _
" FROM Photos"


Dim aSql As String
Dim newBox As Variant
Dim oldBox As Variant
Dim myMagsineName As String
Dim myMagsineId As String
Dim i As Integer


Set db = CurrentDb()


newBox = Forms![boxes]![boxId]
oldBox = Forms![boxes]![oldBoxId]
myMagsineName = Forms![boxes]![magasineName]
myMagsineId = Forms![boxes]![magasineId]


maxPicureId = DMax("pictureId", "Photos", "[magasineId] = '" &
myMagsineId & "' AND [boxId] = " & oldBox & "")
minPicureId = DMin("pictureId", "Photos", "[magasineId] = '" &
myMagsineId & "' AND [boxId] = " & oldBox & "")
i = minPicureId


For i = minPicureId To maxPicureId
sSQL = "Update [Photos] set [boxId] = " & newBox & " where
[boxId] = " & oldBox & " AND [magasineId] = " & myMagsineId & " AND
[pictureId] = " & i & " ;"
CurrentDb.Execute sSQL
i = i + 1
Next i


Exit_RunTheChangeBox:
MsgBox "Box ändrad!!!"
Exit Function


Err_RunTheChangeBox:
MsgBox Err.description
Resume Exit_RunTheChangeBox


End Function


When I come to ' CurrentDb.Execute sSQL
' it all crashes. Can someone pease what I've missed?


Thanks in advance
/Michelle
A pretty desparate one after one week of struggeling and searchin for
an answer
 
A

Albert D. Kallal

Put the following line of code RIGHT before the

debug.print sSQL <---- put this here
CurrentDb.Execute sSQL


Now, run your code....let it crash....open he debug window..and you an see
your sql...

Try cutting and pasting one of the sql statements shown into he query
builder..and run it....

Further, you could even consider posting the above resulting sql here if no
errors in the syntax can be seen by your eyes...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top