Results 1 to 8 of 8
  1. #1
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149

    cannot show SQL query correctly

    When query in SQL Server, the result as below
    Click image for larger version. 

Name:	r1.png 
Views:	17 
Size:	58.2 KB 
ID:	50398
    But when query in Access, it only show that first record correctly, and all other records are the same as first record as below


    Click image for larger version. 

Name:	r2.png 
Views:	15 
Size:	52.6 KB 
ID:	50399
    I just set the recordsource as below
    Code:
    Me.RecordSource = "SELECT * FROM vDispenHistory WHERE PaNo='" & Me.PaNo & "' ORDER BY ReDate DESC"
    I have other forms using the same coding to call data from SQL server, all works, except this one.

    Thanks

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You set the recordsource where? Where is Me.PaNo? Do you requery? Show us some more info to get pertinent answers.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    I first set RecordSource="select * from vDispenHistory" on Property Sheet.
    In Form_Open, I set Me.RecordSource="SELECT * FROM vDispenHistory WHERE PaNo='" & Me.PaNo & "' ORDER BY ReDate DESC"
    Then I set Me.Requery just after
    Me.RecordSource.
    Then Me.PaNo is '10606' as shown in photo 1.


  4. #4
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    In SQL Server, the query shows 19 records.
    Because I use the same PaNo '10606', it is expected to show 19 records in the form.

  5. #5
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    Thanks Gicu's help to evaluate my case.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by uoghk View Post
    I first set RecordSource="select * from vDispenHistory" on Property Sheet.
    In Form_Open, I set Me.RecordSource="SELECT * FROM vDispenHistory WHERE PaNo='" & Me.PaNo & "' ORDER BY ReDate DESC"
    Then I set Me.Requery just after
    Me.RecordSource.
    Then Me.PaNo is '10606' as shown in photo 1.

    If you change the recordsource, no need for Requery.
    You are effectively doing it twice.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by uoghk View Post
    Thanks Gicu's help to evaluate my case.
    So what was the issue?
    Remember these forums are to help other people, not just yourself.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you try to move the code to the form's load event instead?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query Not Summing Correctly
    By cmumphr in forum Queries
    Replies: 4
    Last Post: 11-05-2018, 12:41 PM
  2. Replies: 5
    Last Post: 01-20-2018, 03:40 PM
  3. Replies: 3
    Last Post: 07-20-2014, 08:56 PM
  4. Query not sorting correctly?
    By Areteauu in forum Queries
    Replies: 2
    Last Post: 01-27-2014, 02:37 PM
  5. Replies: 15
    Last Post: 12-10-2012, 06:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums