Problem writing data to table (sql)

G

Guest

Why doesn´t something happen when I run this script?


Private Sub Kommandoknapp90_Click()
On Error GoTo Err_Kommandoknapp90_Click

DoCmd.OpenReport "beställning", acViewPreview


Dim mydb As Database
Dim rst As DAO.Recordset

Set mydb = CurrentDb()
Set rst = mydb.OpenRecordset("SELECT Korddata.*, Korddata.[skriv ut]
FROM Korddata WHERE Korddata.[skriv ut]=Yes);")

rst.MoveFirst

Do Until rst.EOF = True
rst![Levererad] = no
rst![Histdat] = Now()
rst![skriv ut] = yes
rst.Update
rst.MoveNext
Loop

Set rst = Nothing
Set mydb = Nothing

Exit_Kommandoknapp90_Click:
Exit Sub

Err_Kommandoknapp90_Click:

Exit Sub
Resume Exit_Kommandoknapp90_Click

End Sub
 
D

Douglas J. Steele

WHERE Korddata.[skriv ut]=Yes)

looks suspicious to me. Try using True (or -1) instead.

The fact that it compiles doesn't mean anything: compiling doesn't evaluate
the correctness of the SQL string that's going to be run.

Your error handling is suspect as well: if you encounter an error, you're
simply going to quit the subroutine, but the Err object isn't going to get
reset. Try:

Exit_Kommandoknapp90_Click:
Exit Sub

Err_Kommandoknapp90_Click:
MsgBox Err.Description & " (" & Err.Number & ")", _
vbOkOnly + vbCritical
Resume Exit_Kommandoknapp90_Click

End Sub

Leave out the MsgBox if you really don't want to know what the error is.
 

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

Top