Results 1 to 16 of 16

Thread: Opening a Report reliably-Not my SQL statement?

  1. #1

    Thread Starter
    Addicted Member Bazzlad's Avatar
    Join Date
    Jun 2003
    Posts
    227

    Unhappy Opening a Report reliably-Not my SQL statement?

    It's in VBA (Access)
    I have a report which grabs data off an open form *Through a query*
    [Query grabs data off open form-report shows Querys data]

    The problem is it doesn't always open, I get messages like:

    access can't find the field FORMS reffered to in your expression
    or
    the open report action was cancelled.

    The problem is, it seems to be totally random, it won't work, and then I'll reopen and it will/won't. There doesn't seem to be any way to 100% guarentee opening it,,,
    and it needs to be.
    The code I'm using:

    VB Code:
    1. 'Checks if needed field is filled in
    2.     If not Datebox.Value >= "" Then
    3.     MsgBox "Please enter a Date"
    4.     Datebox.SetFocus
    5.     Else
    6.     'Checks if the form sale is the only open form
    7.     For Each frm In Forms
    8.     If frm.Name <> "frmsale" Then
    9.     DoCmd.Close acForm, frm.Name
    10.     End If
    11.     Next frm
    12.     'Hides the listbox, goes forward a record then
    13.     'backwards a record-to make sure the data is
    14.     'saved then re shows the listbox
    15.     List106.Visible = False
    16.     DoCmd.GoToRecord , , acNext
    17.     DoCmd.GoToRecord , , acPrevious
    18.     List106.Visible = True
    19.     'Opens report
    20.     DoCmd.OpenReport "qryreport", acViewPreview


    PLEEEEEEEEEEASE Help, It's been driving me mad for a week or longer now!
    Last edited by Bazzlad; Oct 28th, 2003 at 08:25 AM.
    *And you'll see, Everything you stand for is fake*
    http://www.rhesusrock.com

  2. #2

    Thread Starter
    Addicted Member Bazzlad's Avatar
    Join Date
    Jun 2003
    Posts
    227
    Doesn't anyone have ANY ideas? Maybe a different way of opening the form? Come on guys...
    *And you'll see, Everything you stand for is fake*
    http://www.rhesusrock.com

  3. #3

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    your code doesn't make sure that the form is open, only that no others are.

    how about this instead of your current For loop:

    VB Code:
    1. Dim IsVisible as Boolean
    2. IsVisible = False
    3. For Each frm In Forms
    4.     If LCase(frm.Name) <> "frmsale" Then
    5.       DoCmd.Close acForm, frm.Name
    6.     Else
    7.       IsVisible = True
    8.     End If
    9. Next frm
    10.  
    11. If Not (IsVisible) Then
    12.   'show the form here  (sorry, dont know Access code for it!)
    13. End If

  5. #5

    Thread Starter
    Addicted Member Bazzlad's Avatar
    Join Date
    Jun 2003
    Posts
    227
    *Cries harder*
    It's so dumb. I could handle it if the error was consisitent. But half the time if the report doesnt load, I knock the form into design mode and back and it works. Although sometimes that doesn' work. GRRRRRRRRR
    Thanks anyway Woka!
    *And you'll see, Everything you stand for is fake*
    http://www.rhesusrock.com

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Originally posted by Wokawidget
    Sorry, I don't have a clue about VBA
    It's a stupid language and I find it very complex and very hard to understand *sob*

    Woka
    I'm with you on that one... even your (previously impossible) Multithreading code is easier to work with

  7. #7

    Thread Starter
    Addicted Member Bazzlad's Avatar
    Join Date
    Jun 2003
    Posts
    227
    That code works great Si,

    VB Code:
    1. Dim IsVisible As Boolean
    2.     IsVisible = False
    3.     For Each frm In Forms
    4.     If LCase(frm.Name) <> "frmsale" Then
    5.     DoCmd.Close acForm, frm.Name
    6.     Else
    7.       IsVisible = True
    8.     End If
    9.     Next frm
    10.  
    11.     If Not (IsVisible) Then
    12.     DoCmd.OpenForm "frmsale"
    13.     End If

    But doesn't stop the problem.
    I think the problem may be with the way the report is opened....
    Maybe try making sure the report is shut before I open it...
    ? Damn VBA is retarded.
    Maybe I'll try shutting the report
    *And you'll see, Everything you stand for is fake*
    http://www.rhesusrock.com

  8. #8

    Thread Starter
    Addicted Member Bazzlad's Avatar
    Join Date
    Jun 2003
    Posts
    227
    Do you think as it can't find the field FORMS
    {which is stated in my SQL Statement}
    That there may be a problem in my SQL?
    Here it is:
    Ignore the bracket attack, MS added those for me.
    Code:
    SELECT DISTINCT [tblin].[Make], [tblin].[Phone Model], [tblin].
    [IMEI], [tblin].[Sold?], [tblin].[Sale Number], [tblin].[Price],
    [tblcustomer].[Customer Name], [tblcustomer].[Company], 
    [tblcustomer].[Customer ID], [tblout].[Date]
    FROM tblcustomer, tblin, tblout
    WHERE ((([tblin].[Sold?])=Yes) And (([tblin].[Sale Number])=
    [Forms]![frmsale]![sale number].value) And (([tblcustomer].
    [Customer ID])=[Forms]![frmsale]![customer ID].value) And 
    (([tblout].[Date])=[Forms]![frmsale]![Datebox].value));
    Anything wrong with that?
    *And you'll see, Everything you stand for is fake*
    http://www.rhesusrock.com

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    I think it's ok, just make sure that the values on the form (eg:[sale number].value) have appropriate values.

  10. #10
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Originally posted by si_the_geek
    I'm with you on that one... even your (previously impossible) Multithreading code is easier to work with
    My code makes perfect logical sense, well easy to follow. I find code like that dead easy to work with. Now VBA on the other hand

    Wa

  11. #11

    Thread Starter
    Addicted Member Bazzlad's Avatar
    Join Date
    Jun 2003
    Posts
    227
    Nothing is working.
    I've tried opening the actually query in the BG, refreshing all the data on the form, had a look at my SQL making sure the correct forms amd data are there and still it works sometimes and sometimes not.
    I'm gonna kill something/one.
    Is there like, an add on program for reports-something reliable?
    LONG SHOT.
    *And you'll see, Everything you stand for is fake*
    http://www.rhesusrock.com

  12. #12

    Thread Starter
    Addicted Member Bazzlad's Avatar
    Join Date
    Jun 2003
    Posts
    227
    If I post the project on here, would anyone be willing to have a look through it and try to find the fault?
    Bazz
    *And you'll see, Everything you stand for is fake*
    http://www.rhesusrock.com

  13. #13
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Just post it anyways.
    I won't be able to help as we don't have Access installed at work
    Will be able to have a look when I get home, however I don't know if I would be of any use.

    Woka

  14. #14

    Thread Starter
    Addicted Member Bazzlad's Avatar
    Join Date
    Jun 2003
    Posts
    227
    Here it is.
    The add sale and find sold forms are the problems, as I said, sometimes they'll show the invoice (report) sometimes they won't.

    *please ignore the goto's and .values - it's the only way I can get VBA to do certain things. Trust me on that.*
    Attached Files Attached Files
    *And you'll see, Everything you stand for is fake*
    http://www.rhesusrock.com

  15. #15

    Thread Starter
    Addicted Member Bazzlad's Avatar
    Join Date
    Jun 2003
    Posts
    227
    if anyone wants to dl and have a look feel free, the offer is open purely to Woka!
    *And you'll see, Everything you stand for is fake*
    http://www.rhesusrock.com

  16. #16
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    Originally posted by Wokawidget
    Sorry, I don't have a clue about VBA
    It's a stupid language and I find it very complex and very hard to understand *sob*

    Woka
    The "language" of VBA is VB. So you can't say the language is stupid without saying VB is stupid. The only difference in VBA is that the MS Office application class s exposed. So you would have to say that MS Office application classes are stupid. They are complex because they dodoes of (great) stuff. But you can say the classes are stupid if you want. One thing that is stupid is MS Access. It seems to be designed for non-programmers to handle databases. Of course, good Access developers can do wonders with Access. The problem is that everything gets spread out over tables, queries, forms, macros, VBA, etc. Access leans heavily toward bound controls, and wit all these objects that is very contusive to spaghetti code (without the code even!) This seems to be the case in this...um...case.

    frmSold has a control (List33) that queries qyrnewsold, which in turn has fields that are derived from frmSold. You get a circular reference. If frmSold is not open, List33 cannot query qyrnewsold because the frmSold values it depends on for the query are not set. So it will ask you for the values, and if it doesn't get the values it need it raises the error messages you have been getting.

    The solution is to kill the circular reference. It appears Command149 should create a report based on the values in frmSale. Simply replace the three instances of frmSold in qyrnewsold with frmSale. Now qryrereport is not dependent on values in frmSold when it queries qyrnewsold so you have eliminated the circular reference. If you need List33 to be specifically dependent on the values in frmSold, make one query to be used exclusively by frmSold dependent on frmSold control values, and another query to be used exclusively by used qryrereport dependent on frmSale values.

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