|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
End If without block Ifwithout block If". However it does change the record that i edit. Here is my code: Private Sub cmdUpdate_Click() If (datAudit.Recordset.State And adStateOpen) = adStateOpen Then datAudit.Recordset.Close With datAudit.Recordset.OpenRecordset .Fields("User") = txtUser.Text .Fields("AssetTag") = txtAssetTag.Text .Fields("Product") = txtProduct.Text .Fields("Make") = txtMake.Text .Fields("Model") = txtModel.Text .Fields("S/N") = txtSN.Text .Fields("Site") = txtSite.Text .Fields("Status") = txtStatus.Text .Update End With End If End Sub Can anybody help please?? "baked potato" <bakedpot***@discussions.microsoft.com> wrote in message That error would be caused if the following is all in one line in your code:news:CE79FCD7-7E98-4103-B7FC-E9E97CC6AEFB@microsoft.com... > I get this compile error when i click my update command > button "End If without block If". If (datAudit.Recordset.State And adStateOpen) = adStateOpen Then datAudit.Recordset.Close From your post it is hard to see whether or not that is the case. It could be that the code is all in one line, and that the newsreader at your end or mine has "wrapped" it immediately following the word "Then", or it could be that your code actually does have it in two lines (with the fiurst line ending with the word "Then"). It's a bit difficult to say what I mean because the line might get "hard wrapped" again by the news reader, so let's shorten the variable names to show you what I mean. Does your code look like this: If (d.R.S And a) = a Then d.R.Close .. . . or does it look like this: If (d.R.S And a) = a Then d.R.Close I suspect the former, which would be the cause of your problem. I don't "do" RecordSets so I cannot follow the logic of what it is you are doing, and I cannot therefore say which version you should use to perform that logic, but your standard "If" statements should normally be in one of the following formats (and preferably the latter of the two): If a = b Then doSomething .. . . or If a = b Then doSomething End If The latter requires an End If whereas the former does not, and it looks as though your code is (either deliberately or inadvertently) using the former, which is why the "End If" at the bottom of your example code is throwing the error you are getting. Mike Probably - Inline :-
On Fri, 23 Feb 2007 04:53:27 -0800, =?Utf-8?B?YmFrZWQgcG90YXRv?= <bakedpot***@discussions.microsoft.com> wrote: >I get this compile error when i click my update command button "End If Have you got a vbCrLf after the Then ? Somehow I doubt it.>without block If". However it does change the record that i edit. > >Here is my code: > >Private Sub cmdUpdate_Click() > >If (datAudit.Recordset.State And adStateOpen) = adStateOpen Then Show quoteHide quote >datAudit.Recordset.Close > >With datAudit.Recordset.OpenRecordset > > .Fields("User") = txtUser.Text > .Fields("AssetTag") = txtAssetTag.Text > .Fields("Product") = txtProduct.Text > .Fields("Make") = txtMake.Text > .Fields("Model") = txtModel.Text > .Fields("S/N") = txtSN.Text > .Fields("Site") = txtSite.Text > .Fields("Status") = txtStatus.Text > .Update >End With >End If Indent properly >End Sub >Can anybody help please?? Is the
IF (datAudit...) = asStateOpen then datAudit.recordset.close all on one line? If it is, then there is no IF ... then statement preceding the code before the Endif at the end of your snippet (which, of course, would generate your error) I'll let you fix it Argusy baked potato wrote: Show quoteHide quote > I get this compile error when i click my update command button "End If > without block If". However it does change the record that i edit. > > Here is my code: > > Private Sub cmdUpdate_Click() > > If (datAudit.Recordset.State And adStateOpen) = adStateOpen Then > datAudit.Recordset.Close > > With datAudit.Recordset.OpenRecordset > > .Fields("User") = txtUser.Text > .Fields("AssetTag") = txtAssetTag.Text > .Fields("Product") = txtProduct.Text > .Fields("Make") = txtMake.Text > .Fields("Model") = txtModel.Text > .Fields("S/N") = txtSN.Text > .Fields("Site") = txtSite.Text > .Fields("Status") = txtStatus.Text > .Update > End With > End If > End Sub > > > Can anybody help please?? baked potato wrote:
> I get this compile error when i click my update command button A perfect example of why I would /never/ recommend using VB's one-line > "End If without block If". > If (datAudit.Recordset.State And adStateOpen) = adStateOpen Then > datAudit.Recordset.Close > > With datAudit.Recordset.OpenRecordset .. . . > End With > End If > End Sub "If .. Then" syntax. As you've discovered, it's an ideal way to unbalance your Ifs and End Ifs, resulting in simply /massive/ confusion. With the /possible/ exception of ... Private Sub Form_Resize() If Me.WindowState = vbMinimized Then Exit Sub ... .... I do my very best to /avoid/ the one-line "If .. Then". And Global variables ... honest ... ;-) HTH, Phill W. Just to add to the pile, if various Begin/end constructs exist inside
an IF, the compiler might report this error if any of the End statements for the constructs are missing. Saga -- Show quoteHide quote"baked potato" <bakedpot***@discussions.microsoft.com> wrote in message news:CE79FCD7-7E98-4103-B7FC-E9E97CC6AEFB@microsoft.com... >I get this compile error when i click my update command button "End If > without block If". However it does change the record that i edit. > > Here is my code: > > Private Sub cmdUpdate_Click() > > If (datAudit.Recordset.State And adStateOpen) = adStateOpen Then > datAudit.Recordset.Close > > With datAudit.Recordset.OpenRecordset > > .Fields("User") = txtUser.Text > .Fields("AssetTag") = txtAssetTag.Text > .Fields("Product") = txtProduct.Text > .Fields("Make") = txtMake.Text > .Fields("Model") = txtModel.Text > .Fields("S/N") = txtSN.Text > .Fields("Site") = txtSite.Text > .Fields("Status") = txtStatus.Text > .Update > End With > End If > End Sub > > > Can anybody help please?? You just reminded me - I had a Do... without the closing Loop causing
the same message, when I had this plus several other If/End ifs inside an If/End if (It really pissed me off, all the IF/End If constructs were there!!) Graham Saga wrote: Show quoteHide quote > Just to add to the pile, if various Begin/end constructs exist inside > an IF, the compiler might report this error if any of the End statements > for the constructs are missing. > > Saga "(It really pissed me off,...."
Welcome to the club! <g> Saga -- Show quoteHide quote"Argusy" <argusyNON@SPAMMEslmember.on.net> wrote in message news:45DF5563.20803@slmember.on.net... > You just reminded me - I had a Do... without the closing Loop causing the same message, when I had > this plus several other If/End ifs inside an If/End if > > (It really pissed me off, all the IF/End If constructs were there!!) > > Graham > > Saga wrote: >> Just to add to the pile, if various Begin/end constructs exist inside >> an IF, the compiler might report this error if any of the End statements >> for the constructs are missing. >> >> Saga > It's invariably due to another 'if' without an 'end if', double check the
whole procedure. Show quoteHide quote "baked potato" wrote: > I get this compile error when i click my update command button "End If > without block If". However it does change the record that i edit. > > Here is my code: > > Private Sub cmdUpdate_Click() > > If (datAudit.Recordset.State And adStateOpen) = adStateOpen Then > datAudit.Recordset.Close > > With datAudit.Recordset.OpenRecordset > > .Fields("User") = txtUser.Text > .Fields("AssetTag") = txtAssetTag.Text > .Fields("Product") = txtProduct.Text > .Fields("Make") = txtMake.Text > .Fields("Model") = txtModel.Text > .Fields("S/N") = txtSN.Text > .Fields("Site") = txtSite.Text > .Fields("Status") = txtStatus.Text > .Update > End With > End If > End Sub > > > Can anybody help please?? liamfitz wrote:
> It's invariably due to another 'if' without an 'end if', double check the you clearly have no idea what the word "invariably" means.> whole procedure. Bob Option Explicit Dim A As Long Private Sub Form_Load() If A Then Select Case A End If End Sub --
Need to pull HARD DRIVE serial number in DOS!!!!!
Overflowing a Long Vista Change Specifics Best Vista Setup for Development Printing in IE with no prompt VB6 Simple CD Burner Compairson to a fixed length string Handling pop up window in VB how does a recordset work ? FYI - Daylight Savings Time affects MS apps |
|||||||||||||||||||||||