473,322 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Docmd.openform will not open my form!

52
It's weird - I've used this code all over the place and it has always worked (well, up 'til now!)

I have an instructor FAQs form that has a question and then a button called "See Answer!". When they click the button, another form is supposed to pop up with both the question and the answer. Both forms are based on the same table, which looks like:

Question_ID - an autonumbered primary key
Question - the question
Answer - the answer! : )

In the On_Click event of the button, I have the code:

DoCmd.OpenForm "IKB: Instructor FAQs Display for Instructors", , , "[Question_ID] = " & Question_ID

This should pass the ID of the question (the ID's are correct) and display both the question and the answer. However, NOTHING opens! The form name is spelled correctly, I'm sure of that. What am I missing? Is there something in the form itself that needs to be changed? I've tried comparing every last setting on my other pop-up forms to this one and cannot figure it out.

Any insight would be great! Thanks! (Access 2007)
Feb 21 '10 #1
7 4678
Stewart Ross
2,545 Expert Mod 2GB
Hi. There's no obvious problem with your DoCmd.OpenForm, so you'll need to try a few tests to eliminate possibilities.

First, make sure you don't have an On Error Resume Next in your on-click code - if you do you won't get notification of errors that occur at run-time.

Test 1: Check that the form with the questions and answers opens manually and displays the set of records you would expect it to. Check its name again and make sure it is the same as in your DoCmd.Openform statement. Check also that the Question_ID autonumber field underlying your form is indeed named Question_ID and not Question ID. This is to guard against the automatic substitution of underscores for spaces which is done by the VB editor. Intellisense allows a control named Question ID to be referred to using Me.Question_ID but NOT [Question_ID].

Test 2: In the on-click code remove the Where clause (and all the commas) after the formname in Docmd.Openform. Does the form then open? I would expect it to, because if the form name was not correct an error would be generated that the form could not be found.

Test 3: If the form does open in test 2 then the Where clause is at issue. Add a Where clause back in but instead of referring to the value of Question_ID substitute a known existing question ID (e.g. 15) into the statement:

DoCmd.Openform "IKB: Instructor FAQs Display for Instructors", , , "[Question_ID] = 15"

Does the form then open and display the known question? If it does there is a problem with the question_ID control value passed to the Where clause.

Sorry I can't be more specific with what might be wrong. It is rare for OpenForm to be a problem. I reckon that systematically eliminating potential causes and effects to find the root of this conundrum is the best way forward.

Welcome to Bytes!

-Stewart
Feb 21 '10 #2
Mmmel
52
Thanks for the response, Stewart! I will go through these steps and hopefully figure out what's wrong!

Cheers!
Feb 21 '10 #3
Mmmel
52
Hi again!

OK - I solved the problem and thought I would post the solution up here for anyone else who might be having the same problem. Oh, and you can file the solution under "D" for "duhhhhh..." : )

The code started off as:

DoCmd.OpenForm "IKB: Instructor FAQs Display for Instructors", , , "[Question_ID] = " & Question_ID

I then changed the control names so the code became:

DoCmd.OpenForm "IKB: Instructor FAQs Display for Instructors", , , "[QuestionID] = " & QuestionID

That didn't work, so I simply added square brackets to the last QuestionID like so:

DoCmd.OpenForm "IKB: Instructor FAQs Display for Instructors", , , "[QuestionID] = " & [QuestionID]

I really didn't think I needed them, but after I added them the problem was magically fixed.

Thanks again! Go Canada Go! : )
Feb 27 '10 #4
Stewart Ross
2,545 Expert Mod 2GB
Hi Mmmel. You needed the square brackets to tell the VB environment you were referring to a control from the underlying form. If you just put down NameOfSomething, the VB environment will treat this as the name of a VB variable. Without explicit error checking for non-declared variables, VB will simply assign a null to such a variable - resulting in no match for your filter.

If you had the statement Option Explicit On at the top of your code (which you really should be using) the VB editor would have thrown an 'undeclared variable' compile error when you referred to QuestionID without having a DIM statement matching it.

When you use the square brackets you are telling the VB editor you are referring to a control name, or a field within the data source to which the form is bound.

You could have used the name without brackets by qualifying it explicitly using the Me shortcut (which refers to the underlying form's properties)

"[QuestionID]=" & Me.QuestionID

To sum up, controls in the underlying form are properties of the form, and in referring to them you should make this clear, either using the Me shortcut (as in Me.SomeControlName) or the full reference to the form concerned if, say, you are referring to a control in a different form (as in Forms("YourFormName").SomecontrolName).

-Stewart
Feb 28 '10 #5
Mmmel
52
Hi Stewart!

I just saw this reply today - thanks! I figured it had something to do with it not being recognized as a field name, but I did not know why or how to avoid it in the future. So, I just add the line of code:

Option Explicit On

at the top of the code to avoid this in the future? I ask since I'm having a similar problem with another bit of code. I'm trying to loop through a list of email addresses and fire up a new Outlook message. It works in one database, but when I try pretty well the same code in a different database, it just sits there and looks at me blankly. I've checked all the Options, and all the same libraries and things are referenced. I'm going to add the code above and see if it at least complains! If I can't figure it out, can I post the code back here? Thanks again!
Mar 6 '10 #6
Mmmel
52
Hi again!

Well, I tried putting in the Option Explicit On code. I put it in right below the first line (before any variables were declared) and it gave me a syntax error!

Setting that aside for a minute, can anyone see why this bit of code below does not work? It, once again, will not open anything! This code is behind the On Click event of a button and is supposed to create an email that uses a query to loop through and make the Bcc field. I've checked, and the query is working properly and all the email addresses are there. It just won't make my email!

Anything obviously wrong with this?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command68_Click()
  2. Dim strEMail As String
  3. Dim oOutlook As Object
  4. Dim oMail As Object
  5. Dim strAddr As String
  6. Dim MyDB As DAO.Database
  7. Dim rstEMail As DAO.Recordset
  8.  
  9. Set oOutlook = CreateObject("Outlook.Application")
  10. Set oMail = oOutlook.CreateItem(0)
  11.  
  12. 'Retrieve all E-Mail Addressess in Email: Students Fall
  13. Set MyDB = CurrentDb
  14. Set rstEMail = MyDB.OpenRecordset("Select * From [Email: Students Winter]", dbOpenSnapshot, dbOpenForwardOnly)
  15.  
  16. With rstEMail
  17.   Do While Not .EOF
  18.     'Build the Recipients String
  19.     strEMail = strEMail & ![E-mail] & ";"
  20.       .MoveNext
  21.   Loop
  22. End With
  23. '--------------------------------------------------
  24.  
  25. With oMail
  26.   .To = "something@domain.ca"
  27.   .Bcc = Left$(strEMail, Len(strEMail) - 1)        'Remove Trailing ;
  28.   .Body = ""
  29.   .Subject = ""
  30.     .Display
  31. End With
  32.  
  33. Set oMail = Nothing
  34. Set oOutlook = Nothing
  35.  
  36. rstEMail.Close
  37. Set rstEMail = Nothing
  38. End Sub
Thanks again!
Mar 8 '10 #7
Mmmel
52
I've tried everything. I just CANNOT understand why this works in one database and not another! ARGH...............Going to bed now. I give up! : )
Mar 9 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: chanchito_cojones | last post by:
hi there, I am needing some help with a database I am putting together. The database works off of a main Form, which then has buttons on it that will open up other forms. The problem I am having...
1
by: Nothing | last post by:
I have a form that the user types in a last name to search for then clicks a search button. Based on the information I want to open the form using the SQL Where statement that will pattern match...
3
by: Lyn | last post by:
Hi, I have a Search input form which collects from the user a person's name. I am using LIKE with a "%" suffix in the SQL so that the user does not have to type in the full name. When they hit...
15
by: Thelma Lubkin | last post by:
formA determines some_where and some_value and issues docmd.close ,Me docmd.openform "formB", , ,some_where, , ,some_value formB receives the correct some_where and some_value After...
8
by: John Welch | last post by:
I have a command button with the following code: DoCmd.OpenForm "frmSearchAssignments", , , "SearchAssignmentID = 1" (SearchAssignmentID is the PK, auto number) When it runs, the form opens but...
2
by: Mike | last post by:
I am trying to open a search results form based on the input from a prompt form. I am using the following code: --- Begin Code --- Private Sub btnSearch_Click() 'Dim Variable and assign data...
2
by: rturpyn | last post by:
I want to simply open a form, I don't want to limit the records returned. I'm using the code.... DoCmd.OpenForm "frm_GSG_Access_Rights", acFormDS, , When I enter something in the where...
3
by: gavm360 | last post by:
Hello, im trying to open a form from an dialog box form: the button on the dialog box has this on the onclick event: DoCmd.OpenForm "frmCASES_UNION", acViewNormal, , "MCH_CASECODE = #" &...
1
by: RAG2007 | last post by:
Hi all, Have a question I can't get around. I've done this before and for some reason can't get it to work this time. I'm opening a form through docmd.openform, and trying to get it to open an...
1
by: rdsandy | last post by:
Hi, I am using Access 2003. I have a list box on a form which has 6 columns in it, with data taken from a table. I have an unbound text box which holds the ID number for the selected item in the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.