Results 1 to 12 of 12
  1. #1
    DenisM is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Location
    Sleaford Lincs
    Posts
    29

    I need help using DoCmd.OpenForm

    Hello, I hope somebody can give me some help.


    I created a system in Access to catalogue my banknotes.
    One of the features is to display a country profile from a form (frmCountryProfiles), then view the country's banknotes by selecting "View Banknotes" which opens form (frmSelectedCountriesBanknotesV3), see Attachments A and B.

    This is the command used when "View Banknotes is selected: DoCmd.OpenForm "frmSelectedCountriesBanknotesV3", acNormal, , "Country_Code = '" & Me.Country_Code & "'"
    So far every thing works fine.

    I recently decided to add a Countries Index form, see Attachment C.
    The idea is to select a country this would call Country Profiles and display the selected country, then call Selected Country Banknotes as above.
    I cannot get this to work.
    I have used the following examples to open form (frmCountryProfiles) from form (frmCountriesIndex), see Attachments F and G.
    On Attachment G both OpenForm commands do not work, the first example gives a syntax error in string ,the second causes the program to exit and return to This PC > Documents.

    If you need more information, I will supply.
    Thank you for any help.
    Denis



    Click image for larger version. 

Name:	Attachment A .png 
Views:	36 
Size:	178.9 KB 
ID:	46185Click image for larger version. 

Name:	Attachment B .jpg 
Views:	35 
Size:	172.6 KB 
ID:	46186Click image for larger version. 

Name:	Attachment C.png 
Views:	35 
Size:	33.8 KB 
ID:	46187Click image for larger version. 

Name:	Attachment F.jpg 
Views:	35 
Size:	52.2 KB 
ID:	46189Click image for larger version. 

Name:	Attachment G.jpg 
Views:	34 
Size:	63.3 KB 
ID:	46190

  2. #2
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Hi Denis!

    Why you use the form "frmWorldBanknotes" while you want to open the form "frmCountryProfiles"?

    Try:
    Code:
    DoCmd.OpenForm "frmCountryProfiles",acNormal,,"Country_Name='Albania'"
    Code:
    DoCmd.OpenForm "frmCountryProfiles",acNormal,,"Country_Name='Bulgaria'"
    Code:
    DoCmd.OpenForm "frmCountryProfiles",acNormal,,"Country_Name='Ireland, Republic of'"
    (you have two single quote in the last command, so, that's why you get the error)

    Cheers,
    John

  3. #3
    DenisM is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Location
    Sleaford Lincs
    Posts
    29
    Quote Originally Posted by accesstos View Post
    Hi Denis!

    Why you use the form "frmWorldBanknotes" while you want to open the form "frmCountryProfiles"?

    Try:
    Code:
    DoCmd.OpenForm "frmCountryProfiles",acNormal,,"Country_Name='Albania'"
    Code:
    DoCmd.OpenForm "frmCountryProfiles",acNormal,,"Country_Name='Bulgaria'"
    Code:
    DoCmd.OpenForm "frmCountryProfiles",acNormal,,"Country_Name='Ireland, Republic of'"
    (you have two single quote in the last command, so, that's why you get the error)

    Cheers,
    John
    Hello John,

    Thank you for your response. Unfortunately these do not work, when the command is executed it just exits out of Access.

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    First thing I noticed, and its usually the first thing I look for, Is that you do not have Option Explicit declared.
    (Its a personal thing that drives me crazy.)
    You should add it to all your modules and then compile your code.
    You can set "Require Variable Declaration" in the VBE, go to Tools>options>editor, and it will automatically add it going forward.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,411
    perhaps your country profile forms does not include a field called country_name in the recordsource. Might be called something else or might actually be a number because you are using lookups in the table.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Denis,

    For form frmCountryProfilescheck the recordsource when in design view, and post it.

  7. #7
    DenisM is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Location
    Sleaford Lincs
    Posts
    29
    Hello,
    The recordsource is qryCountryProfiles. What do you mean by post it?
    Thanks
    Denis.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Go to design view of your query; select SQL view; then copy the SQL; and paste it in the thread.

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Do you have a field name Country_Name in qryCountryProfiles? What Orange means is to post a screen shot of your query in design view in here (or the entire SQL statement or even better both).

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

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Missing field should not cause Access to shutdown. Should trigger a popup input prompt.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    DenisM is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Location
    Sleaford Lincs
    Posts
    29
    Hello,
    SQL as requested.

    SELECT tblCountries.Country_Name, tblCountries.Country_Official_Name, tblStatus.Status_Description, tblMonetarySystems.Monetary_System_Name, tblCountries.Country_Succeeded_By, tblCountries.Country_Today_Part_Of, tblCountries.Country_Other_Details, tblFlags.Flag_Image, tblFlags.Flag_Image.FileName, tblStatus.Status_Description, tblCountries.Country_Map, tblCountries.Country_Code
    FROM (((tblFlags INNER JOIN ((((tblMonetarySystems INNER JOIN ((tblStatus INNER JOIN (tblCountries INNER JOIN tblCountriesStatusJoin ON tblCountries.[Country_ID] = tblCountriesStatusJoin.[CSJ_Country_Id]) ON tblStatus.[Status_ID] = tblCountriesStatusJoin.[CSJ_Status_ID]) INNER JOIN tblCountriesMonetarySystemsJoin ON tblCountries.Country_ID = tblCountriesMonetarySystemsJoin.CMSJ_Country_ID) ON tblMonetarySystems.Monetary_System_ID = tblCountriesMonetarySystemsJoin.CMSJ_Monetary_Syst em_ID) INNER JOIN (tblIssuers INNER JOIN tblIssues ON tblIssuers.Issuer_ID = tblIssues.Issue_Issuer_ID) ON tblMonetarySystems.Monetary_System_ID = tblIssuers.Issuer_Monetary_System_ID) INNER JOIN tblStatusMonetarySystemsJoin ON (tblMonetarySystems.Monetary_System_ID = tblStatusMonetarySystemsJoin.SMSJ_Monetary_System_ ID) AND (tblStatus.Status_ID = tblStatusMonetarySystemsJoin.SMSJ_Status_ID)) INNER JOIN tblCountriesFlagsJoin ON tblCountries.Country_ID = tblCountriesFlagsJoin.CFJ_Country_ID) ON tblFlags.Flag_ID = tblCountriesFlagsJoin.CFJ_Flag_ID) INNER JOIN tblFlagsMonetarySystemsJoin ON (tblFlags.Flag_ID = tblFlagsMonetarySystemsJoin.FMSJ_Flag_ID) AND (tblMonetarySystems.Monetary_System_ID=tblFlagsMon etarySystemsJoin.[FMSJ_Monetary_System_ID])) INNER JOIN tblStatusFlagsJoin ON (tblFlags.Flag_ID = tblStatusFlagsJoin.SFJ_Flag_ID) AND (tblStatus.Status_ID = tblStatusFlagsJoin.SFJ_Status_ID)) INNER JOIN tblBanknotes ON tblIssues.Issue_ID = tblBanknotes.Banknote_Issue_ID
    WHERE (((tblCountries.Country_Region) Not Like "CU"))
    ORDER BY tblCountries.Country_Code, tblBanknotes.Banknote_TBB_Pick_Nos;

    Thank you

    Denis

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,910
    Jeez, how are you or anyone else meant to read that?


    Code:
    SELECT     tblcountries.country_name,
               
    tblcountries.country_official_name,
               
    tblstatus.status_description,
               
    tblmonetarysystems.monetary_system_name,
               
    tblcountries.country_succeeded_by,
               
    tblcountries.country_today_part_of,
               
    tblcountries.country_other_details,
               
    tblflags.flag_image,
               
    tblflags.flag_image.filename,
               
    tblstatus.status_description,
               
    tblcountries.country_map,
               
    tblcountries.country_code
    FROM       
    (((tblflags
    INNER JOIN 
    ((((tblmonetarysystems
    INNER JOIN 
    ((tblstatus
    INNER JOIN 
    (tblcountries
    INNER JOIN tblcountriesstatusjoin
    ON         tblcountries
    .[Country_ID] = tblcountriesstatusjoin.[CSJ_Country_Id])
    ON         tblstatus.[Status_ID] = tblcountriesstatusjoin.[CSJ_Status_ID])
    INNER JOIN tblcountriesmonetarysystemsjoin
    ON         tblcountries
    .country_id tblcountriesmonetarysystemsjoin.cmsj_country_id)
    ON         tblmonetarysystems.monetary_system_id tblcountriesmonetarysystemsjoin.cmsj_monetary_syst em_id)
    INNER JOIN (tblissuers
    INNER JOIN tblissues
    ON         tblissuers
    .issuer_id tblissues.issue_issuer_id)
    ON         tblmonetarysystems.monetary_system_id tblissuers.issuer_monetary_system_id)
    INNER JOIN tblstatusmonetarysystemsjoin
    ON         
    (
                          
    tblmonetarysystems.monetary_system_id tblstatusmonetarysystemsjoin.smsj_monetary_system_ id)
    AND        (
                          
    tblstatus.status_id tblstatusmonetarysystemsjoin.smsj_status_id))
    INNER JOIN tblcountriesflagsjoin
    ON         tblcountries
    .country_id tblcountriesflagsjoin.cfj_country_id)
    ON         tblflags.flag_id tblcountriesflagsjoin.cfj_flag_id)
    INNER JOIN tblflagsmonetarysystemsjoin
    ON         
    (
                          
    tblflags.flag_id tblflagsmonetarysystemsjoin.fmsj_flag_id)
    AND        (
                          
    tblmonetarysystems.monetary_system_id=tblflagsmon etarysystemsjoin.[FMSJ_Monetary_System_ID]))
    INNER JOIN tblstatusflagsjoin
    ON         
    (
                          
    tblflags.flag_id tblstatusflagsjoin.sfj_flag_id)
    AND        (
                          
    tblstatus.status_id tblstatusflagsjoin.sfj_status_id))
    INNER JOIN tblbanknotes
    ON         tblissues
    .issue_id tblbanknotes.banknote_issue_id
    WHERE      
    (((
                                                
    tblcountries.country_regionNOT LIKE "CU"))
    ORDER BY   tblcountries.country_code,
               
    tblbanknotes.banknote_tbb_pick_nos
    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

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

Similar Threads

  1. I need help using DoCmd.OpenForm
    By DenisM in forum Forms
    Replies: 9
    Last Post: 06-22-2021, 09:55 PM
  2. Replies: 3
    Last Post: 10-27-2017, 04:10 AM
  3. DoCmd.OpenForm with 2 Where Conditions
    By CharissaBelle in forum Programming
    Replies: 3
    Last Post: 10-19-2016, 09:32 AM
  4. What actually happens at docmd.openform
    By Beorn in forum Programming
    Replies: 4
    Last Post: 01-05-2011, 02:19 PM
  5. DoCmd.OpenForm Modification
    By alsoto in forum Forms
    Replies: 6
    Last Post: 05-01-2009, 07:28 AM

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