Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
UPDATE SQL Not Working
Gary Becker 
     
16 months ago
I'm trying to reorder the HCOrder field in a list of vehicles. I can't figure out why this UPDATE SQL doesn't work. It gives me a Run-time error '3061': Too few parameters. Expected 1.   I've googled that and it says that error is when a field is misspelled or missing So I'm at a loss.

DetailsPrivate Sub Reorder_Click()

    Dim rs As Recordset
    Dim X As Long
    
    Set rs = CurrentDb.OpenRecordset("tblVehicleList")
    
    DoCmd.GoToControl "HCOrder"
    DoCmd.GoToRecord , , acFirst
    
    X = 0
    While Not rs.EOF
        X = X + 1
                
        CurrentDb.Execute "UPDATE tblVehicleList SET tblVehicleList.HCOrder = X"
        
    rs.MoveNext
    Wend
    
    rs.Close
    
End Sub

Kevin Robertson  @Reply  
           
16 months ago
The variable should be outside the quotes.

    CurrentDb.Execute "UPDATE tblVehicleList SET HCOrder=" & X
Adam Schwanz  @Reply  
           
16 months ago
Maybe I haven't had my coffee yet, or I don't use CurrentDB.Execute like that, but isn't that going to set every record to X every time it goes to a new record? Resulting in all of them being the same?
Adam Schwanz  @Reply  
           
16 months ago
This is simpler :P.
While Not Rs.EOF
X=X+1
rs.edit
rs!HCOrder=X
rs.update
rs.movenext
wend


Unless you're trying to make them all the same for some reason. But thats not what I think when I hear "reorder list"
Gary Becker OP  @Reply  
     
16 months ago
Adam,
You are exactly right on both counts. It updated that field (I think to the total number of records) on every record. And it was not what I wanted.

What I ended up doing was adding a new field to the table Called NewOrder and then using the following code. So the first part of the code updates the field NewOrder with sequential numbers, then it updates the field HCOrder with those values. It could be that your code would do it all at once. Here is the code I finally got to work for me.

    X = 0
    While Not IsNull(VehicleID)
        X = X + 1
        NewOrder = X
    DoCmd.GoToRecord , , acNext
    Wend
    
    DoCmd.GoToControl "HCOrder"
    DoCmd.GoToRecord , , acFirst

    While Not IsNull(VehicleID)
    
        HCOrder = NewOrder
        DoCmd.GoToRecord , , acNext
    
    Wend

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 11:27:13 AM. PLT: 0s