Combo Box and SubForm

G

Guest

I have a combo box that lists BOE ID numbers on a form (frmPricing). Once the
user selects the choice, I want a subform (sfrmPricingA) to fill in
automatically.

My code is:

Private Sub cboBOENo_AfterUpdate()
sSQL = "SELECT * FROM BOE WHERE " & _
"id_BOE = " & Chr(39) & Me!cboBOENo & Chr(39)

Me!sfrmPricingA.Form.RecordSource = sSQL

End Sub

I get an error message that "You canceled the previous operation". When I
hit the debug button the "Me!sfrmPricingA.Form.RecordSource = sSQL" is
highlighted in yellow.

How do I get this to work?
 
C

Carl Rapson

Put a breakpoint on the line where the error occurs, and at the break in the
Immediate window enter "? sSQL". Paste the resulting SQL code that's
displayed into the SQL View of a new (blank) query and see if you get the
results you expect. If an error occurs, it might have enough informaiton for
you to track down the error.

Carl Rapson
 
G

Guest

Thanks for the suggestions Carl!

Carl Rapson said:
Put a breakpoint on the line where the error occurs, and at the break in the
Immediate window enter "? sSQL". Paste the resulting SQL code that's
displayed into the SQL View of a new (blank) query and see if you get the
results you expect. If an error occurs, it might have enough informaiton for
you to track down the error.

Carl Rapson
 
G

Guest

Hi Carl,

I'm very new to VBA and thought I could figure out what you said below, but
I'm having problems with it. So my questions are:

Is a breakpoint that brownish red dot that appears on the side of the Visual
Basic code when you click there?

I put the brownish red dot next to the code that was highlighted
automatically by VBA, and then put "? sSQL" in the immediate window. I then
hit the return key and got the following:

Compile Error: expecting line number or label or statement or end of
statement.

Sorry to say that I don't understand what the compile error means.

Am I doing this correctly? If not, could you explain in more detail? If I'm
doing this correctly, could you explain where I should look for answers to
the compile error statement?
 
C

Carl Rapson

Yes, that is the breakpoint. When you run your code, it will "break" at that
line (the line will turn yellow) and pause. When the code execution breaks
at the breakpoint, open the immediate window by pressing Ctrl+G (or select
Immediate Window from the View menu at the top of the Code window).

So here are the steps:

1. Set the breakpoint.

2. Run the form and make a selection in the combo box.

3. When execution pauses, go to the Code window and open the Immediate
Window as described above.

4. Type "? sSQL" (without the quotes) in the Immediate Window and press
Enter.

5. Copy the resulting SQL code (highlight it and press Ctrl+C).

6. From the Database screen, open a new Query, select Design View, close the
Show Table window (don't select a table), and then switch to SQL View
(should be in the upper left of the screen, just below the File menu).

7. Delete whatever is in the SQL View window and paste your SQL code into
the window with Ctrl+V.

8. by Execute the SQL code by clicking the reddish-brown exclamation point
in the tookbar (or select Run from the Query menu).

If there is a problem in the SQL code, you should get an error. The error
might give you enough information to make a determination as to the problem.

Carl Rapson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top