Results 1 to 30 of 30

Thread: [RESOLVED] ReQuery a form

  1. #1

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Resolved [RESOLVED] ReQuery a form

    How would one go about doing this?

    My problem is -- I have a form, and when I edit the data, then click the save button, the table is update...However, I have to close the form and reopen it for the changes to appear.

    I have tried RecordSet.ReQuery, but it gives me an error on some of my other code, stating that the value isn't valid.

    I was thinking of just editing the recordsource and updating, but I don't know how to make this code work in a SQL statement in VB code :/

    VB Code:
    1. SELECT DCount("ID","WorkerInformation","ID<'" & [ID] & "'")+1 AS SeqNr, * FROM WorkerInformation;

    As the double quotes raise an error...SO I tried it with single quotes, but that didn't work either...

    I'm gonna keep plugging away at this, but if anyone can help me Id really appreciate it


    And I have a sinking suspicion I am going to owe Danny another rep

  2. #2
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    Errm Yup..

    Hello again..

    VB Code:
    1. Dim cr As String
    2. cr = Chr(34)
    3. strsql = "SELECT DCount(" & cr & "ID" & cr & "," & cr & "WorkerInformation" & _
    4.  cr & "," & cr & "ID<'" & cr & " & [ID] & " & cr & "'" & cr & ")+1 AS SeqNr, * FROM WorkerInformation;"

    That should do it... test it with a message box to see if it replicates what is in the recordsource or controlsource
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: ReQuery a form

    here
    I think it may be jro (jet something objects) which has a refreshcache property. Have a look and see whether it clears the problem.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    But then Again..

    VB Code:
    1. Me.Requery

    Should do the job.. not

    VB Code:
    1. Me.Recordset.Requery
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  5. #5

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    my access doesn't seem to support JRO, I cant even declare a new object...

    And Danny, although that was the right SQL, that loaded me to the first record everytiem I ran it..so its no good



    is there a way to requery it without it loading to the first record again?


    and I tried Me.RecordSet.ReQuery and just Recordset.ReQuery and Me.ReQuery...they all raised the error

    "The value you entered isnt valid for this field"


    Although It is inputting a name "Travis Smith" into a textbox....
    Last edited by kfcSmitty; Aug 11th, 2005 at 09:37 AM.

  6. #6
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    If this is the code I did yesterday.. then you would just need to call the combobox change event with the lngCurrRec variable as this should still reflect the last chosen record number..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  7. #7

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    yeah..problem is, it calls the form_current before it does the click event...Oh well..Guess I will keep working on it

  8. #8
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    What are you doing in the form current as the error sounds like it is hitting here
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  9. #9

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    form_current is where i populate all the fields on the form, as well as call some other procedures for calculations

    If I can get CurrentNr to change before form_current is called, then it should work fine

  10. #10

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    when i change the recordsource it calls the form_current...found that out

    So now I tried just calling form_current at the end of the ID_Click, and it still wont load the right values...it doesnt even save the values to the table anymore...


    oh and danny, i did edit your code a tiny bit..instead of having most of my textboxes bound to a field, I am populating them manually, so that if the user edits the item it isnt automatically saved
    Last edited by kfcSmitty; Aug 11th, 2005 at 10:27 AM.

  11. #11
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    I thought I'd written that to just move the recordset, and the form was based on the recordset (Bound) so that any changes made should reflect directly into the table..

    You shouldn't need to repopulate the form with the record's values as the movement of the recordset should handle this.. any unbound controls will need to be manipulated in the form_current event..

    Me tinks... its gonna have to be an upload if possible...
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  12. #12

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    an upload? and yeah...the problem was, if the user editted a bound form, the changes were automatically changed..but if they editted the ID or Name, then they would have to click a save button...very confusing

    So I decided to make everything save with the click of the save button...but now this comes up...

    The way I am saving the record is as follows

    VB Code:
    1. Dim rsSave As ADODB.Recordset
    2. Dim SaveString As String
    3. Set rsSave = New ADODB.Recordset
    4. SaveString = "SELECT * FROM WorkerInformation WHERE ID ='" & ID.Value & "'"
    5. rsSave.Open SaveString, cn, adOpenKeyset, adLockPessimistic, adCmdText
    6.     'If rsSave.Fields("ID") = ID.Value Then
    7.         rsSave.Fields("ID") = ID.Value
    8.         rsSave.Fields("Name") = txtName.Value
    9.         rsSave.Fields("Level") = Level.Value
    10.         rsSave.Fields("Payband") = Payband.Value
    11.         rsSave.Fields("MaxPayband") = MaxPayband.Value
    12.         rsSave.Fields("FullSalary") = txtSalary.Value
    13.         rsSave.Fields("Classification") = cboClassifications.Value
    14.         rsSave.Fields("Account") = Account.Value
    15.         rsSave.Update
    16.         rsSave.Close
    17. Call ID_Click

    Which tends to save the record, but i have to click to the next record, and then back, before it shows the updated record

  13. #13
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    By upload I mean, if possible upload a zip of the database with just the table and form.. You can sample the data if its confidential.. I would probably be able to fix it by seeing it, better than trying to write it.

    You could possibly pull the recordset into memory of the form and then allow the user to change what they want.. the form_unload event would then repopulate the table with the information..

    See if you can post the database and I'll take a look to see what I can do..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  14. #14

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    Okay..this is kind of confidential information....But I guess since the records I have here are all completely made up by me..and so are the #'s...it doesnt really matter at this point

    the errors I am having are on frmWorkerInformation
    Last edited by kfcSmitty; Feb 7th, 2008 at 05:27 PM.

  15. #15
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    Looking at it... it's gonna take a while I think there could be some code in here that needs amending or possibly removing..

    I see this has been done with ADO.. any objections to switching this to DAO, as I can work quicker and smarter with this.. plus I get a connection error on trying to Shift click my way into the database.. Obviously your start-up form sets this connection, I'll have to change that to a module, so I can re-initialise it from anywhere
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  16. #16
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    I think that we'll have to forget about the rep point for this one..

    A family size bucket would be better..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  17. #17

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    yes, main form sets the connection

    And I would rather you not switch to DAO...as I have absolutely no experience with it...

  18. #18
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    It's a lot easier to get to grips with inside access than ADO
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  19. #19

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    but im not having a problem calling the data or anything...the problem is with it staying on the same record and updaing the values.....

    Sigh..I so shoulda taken an easier job this summer

  20. #20
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    Double check that cose when I moved to a different record and then back again the changes had vanished...
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  21. #21

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    blehh..its the same problem as yesterday....if i run form_current right after the save code goes..it errors. But if i Click a button after the save, it works fine!

  22. #22

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    works now I didn't think i could use Recordset..so I was using a new recordset to save...Using the form's recordset to do it worked like a charm

  23. #23
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    Another approach to this would be to grab the recordset as an array, place the calculated values into an array with the same row dimension and the allow the user to make as many changes as they want.. but not actually place the values back into the table until the form closes..

    Or possibly use a temporary holding table to store the changes and then delete the original and rename the temporary..

    Well I'm glad you got it resolved...

    Damn Gonna miss that bucket now...
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  24. #24

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    bucket? o.0 And well its somewhat resolved lol..i can update everything except the level for some reason :/

    and dude, you gained like 14 reps since yesterday :/
    Last edited by kfcSmitty; Aug 11th, 2005 at 01:26 PM.

  25. #25
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    Bucket... KFC.. you used to work there...

    You didn't get that

    I helped Hack out..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  26. #26

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    ahh bucket har har har Its been like a yeah and a half since i stopped working there (although theyve been bugging me to go back, so i might do it during the school year)


    Programming is making my head hurt..my Payband, MaxPayband, Name, ID, and Salary fields all work properly..but my anniversary and level dont! lol stupid stupid

  27. #27
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    shall we try DAO, arrays and a re-build of the form.. ??

    ADO is trickier than DAO.. you'll pick it up very quickly and you'll see why M$ reset it as a default reference in Access 2K3
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  28. #28

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    naw naw, now that its just down to some debugging with code i am familiar with this shouldnt be too much of a problem

    Ive only given out 1 rep since yesterday 9 more to go till i can rep u again lol

  29. #29
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: ReQuery a form

    take your time.. I'm not out for the Rep (just keep getting it ) I need to find something to Rep yet..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  30. #30

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ReQuery a form

    finally works 100% now *marks resolved*

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width