Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 3020 - Please help 2

Status
Not open for further replies.

k4ghg

Technical User
Dec 25, 2001
191
US
I have a data base and one of the fields has the (ALLCAT4.Type) has the word SHARE, FREE AND PAY. I am trying to create an HTML file with the data and depending of the TYPE, have some output. But when I get to the:

If rs(3) = "SHARE" Then
rs(3) = "Share"
End If

statement it bombs with a 3020 error ( Update or Cancelupdate Addnew or Edit). Any help or suggestions would be appreciated. Thanks Ronnie

----------------------------------------------------------
Option Compare Database

Sub HTMLout()
Dim db As Database
Set db = CurrentDb

SQL = "SELECT ALLCAT4.GROUP, ALLCAT4.PROGRAM, ALLCAT4.NUM, ALLCAT4.TYPE, ALLCAT4.VERSION, ALLCAT4.COMMENTS FROM ALLCAT4 WHERE ALLCAT4.GROUP = 'BF'"
Set rs = db.OpenRecordset(SQL)
Close #1

Open "c:\testout.htm" For Output As #1

Print #1, "<HTML>"
Print #1, "<head>"
Print #1, "<title>Section Name</title>"
Print #1, "</head>"
Print #1, "<BODY bg color ="; Chr$(34) & "#ffffff" & Chr$(34) & "LINK=" & Chr$(34) & "#ffff00" & Chr$(34) & " VLINK=" & Chr$(34) & "#800080" & Chr$(34) & " ALINK=" & Chr$(34) & "#ff0000" & Chr$(34) & " LEFTMARGIN = "; Chr$(34) & "25%"; Chr$(34) & ">"
Print #1, "<center>"

Print #1, " <table border= 0 cellpadding= 0 cellspacing= 0 width=100%>"

' Loop is for testing '
For x = 1 To 10

Print #1, "<tr>"
Print #1, "<td width = 10%><font Color = Blue>"; rs(2); "</font></td>"
Print #1, "<td width = 55% align = left>"; rs(1)
Print #1, "</td>"

If rs(4) > "" Then
Print #1, " <td width = 15% align = left> rs(4); "</td>"
End If


If rs(3) = "PAY" Then
rs(3) = "Red"
End If

If rs(3) = "FREE" Then
rs(3) = "Green"
End If

' ******** Here if the problem line *****
'Changing the order of If Statements and using If- Then- Else IF doesn't help

If rs(3) = "SHARE" Then
rs(3) = "Share"
End If

Print #1, "<td width = 20% align = Left>"; rs(3)
Print #1, "</td>"
Print #1, "</tr>"
Print #1, "<tr>"
Print #1, "<td colspan = "; 6; " align = left>"; rs(5)
Print #1, "</td>"
Print #1, "</tr>"
Print #1, "<tr><td><p><br></p></td></tr>"
rs.MoveNext
x = x + 1
Next

Print #1, "</table>"
Close #1

rs.Close
db.Close
End Sub
 
Hi k4g,

I take it that none of the other IF options have been TRUE before this, as they would also crash.

I may be wrong, but try this:
[tt]
If rs(3) = "SHARE" Then
rs.edit
rs(3) = "Share"
rs.update
End If
[/tt]
If this works, you'll need to add rs.edit and rs.update to the other IF statements also.

ATB

Darrylle


Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
I am wondering if you really want to update the value in your Type field within this procedure. For example, you would be permanently changing it to "Red" if it currently is "PAY".

My guess is that what you want it to stay as "PAY" but to display "Red" in your HTML. In that case, I would store it in a variable, i.e.

Code:
  Dim strType As String

  If rs(3) = "PAY" Then
   strType = "Red"
  End If

  If rs(3) = "FREE" Then
    strType = "Green"
  End If

  If rs(3) = "SHARE" Then
    strType = "Share"
  End If

  Print #1, "<td width = 20% align = Left>"; strType

 
Joe,

Nicely spotted, however, if we are to provide technical help AND application business rule definition - why don't we produce the application off-line for them and email it to them?

This is a question regarding a error code, which has or has not been answered correctly.
Your addition has opened up a new can of worms - totally unrelated to the title of the question.

When Tek-Tips users open this thread - they'll expect an answer to an error message, but get a totally unrelated answer related to application logic.

ATB

Darrylle



Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
Darryles said:
When Tek-Tips users open this thread - they'll expect an answer to an error message, but get a totally unrelated answer related to application logic.
Answering only the pure technical question is not very helpful if all you are doing is allowing the OP to implement flawed logic. This is a discussion forum, not a FAQ, and those reading the threads must have the wits to judge how useful the advice (which can often be biased or just plain wrong) is to them.
 
Joe,

No prob, however, I do hope that you will now babysit this thread during it's entire life (you won't be helping many other more deserving threads in that case).

What you have already missed, is the fact that a CASE statement would be more suited than IF .. THEN.

Or perhaps you were going to wait until later to expand the thread even further?

ATB

Darrylle

Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
I don't feel under any obligation to add to the thread, or even monitor it for that matter. You answered the original question, and I pointed out another problem. In my opinion the thread is closed, unless someone notices another bug (IF-THEN vs. CASE statement isn't a bug, it's just a question on good programming style).

I don't understand your objections for my contribution to this thread. I think I've saved the OP time and aggravation in dealing with another bug - what's your objection to that?
 
Darrylle,
You been around here long enough to know that often an OP asks for a specific fix, but they are unaware of other fundamental problems. You see this all the time with non-normalized data bases, where the user wants a complex function to do what would be a simple task if the data was normalized. It just does not make much sense to me to help them with the "band-aid" when the underlying foundation is broken. I believe the intent is to help people learn not feed them a quick answer and send them on their way. In fact I have had other MVPs give me a "talking to" when I "give the fish" and not teach the OP "how to fish". But I agree with Joe and do not understand your objection. By the way it is highly discouraged to email to a poster. The exchanging of email addresses on the site invites spam.

Joe
I would have agreed with you if you used a "if then else" and then it would be equivalent to a select case. However, in your construct all three cases are always tested even if the first condition is met. With modern systems no one really cares. However, "good programming" would be the select case or if then else.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top