problem with data entry form

M

martinmike2

Hello,

I have a form with several combo boxes on it that need to combine into
one value.

cboRCN: selects from a set of unique numbers that code job titles
cboRCN_Qual: selects from a set of unique numbers that code payranges

if cboRCN = 6300 and cboRCN_Qual = 7, I would need to combine these
values to make 63007 ( the code that that particular job/payrange.
I can do this via:

Private Sub cmdSAVE_Click
dim A_RATE as string, D_RATE as string
A_RATE = (me.RCN & me.RCN_QUAL)
end sub

now, here is where my problem arises, when i try to run the code i get
an error saying that the module cannot be compiled.

This is a data entry form only, and is not used to "browse" records.
Is there a different procedure for dealing with these types of forms?

My next problem after that is solved is then putting this value into a
table along with other information on the form.
 
B

BruceM

What happens when you try to compile the code? Where does the compiling
fail?

What is the point of assigning a variable to a string variable in the
command button code? You have not done anything with the variable, and its
value is lost as soon as the cmdSave code has run.

You should just combine the values as needed. As the Control Source of an
unbound text box you could have:
=[cboRCN] & [cboRCN_QUAL]
You could use a similar expression in a calculated column in a query:
NewValue: =[RCN] & [RCN_QUAL]
This assumes RCN and RCN_QUAL are fields in the query's record source.

This expression, or any VBA code that does not specify a combo box column,
uses the values from the combo box bound columns (specified on the property
sheet for the combo boxes).
 
M

martinmike2

What happens when you try to compile the code?  Where does the compiling
fail?

What is the point of assigning a variable to a string variable in the
command button code?  You have not done anything with the variable, andits
value is lost as soon as the cmdSave code has run.

You should just combine the values as needed.  As the Control Source ofan
unbound text box you could have:
=[cboRCN] & [cboRCN_QUAL]
You could use a similar expression in a calculated column in a query:
NewValue: =[RCN] & [RCN_QUAL]
This assumes RCN and RCN_QUAL are fields in the query's record source.

This expression, or any VBA code that does not specify a combo box column,
uses the values from the combo box bound columns (specified on the property
sheet for the combo boxes).




I have a form with several combo boxes on it that need to combine into
one value.
cboRCN: selects from a set of unique numbers that code job titles
cboRCN_Qual: selects from a set of unique numbers that code payranges
if cboRCN = 6300 and cboRCN_Qual = 7, I would need to combine these
values to make 63007 ( the code that that particular job/payrange.
I can do this via:
Private Sub cmdSAVE_Click
dim A_RATE as string, D_RATE as string
A_RATE = (me.RCN & me.RCN_QUAL)
end sub
now, here is where my problem arises, when i try to run the code i get
an error saying that the module cannot be compiled.
This is a data entry form only, and is not used to "browse" records.
Is there a different procedure for dealing with these types of forms?
My next problem after that is solved is then putting this value into a
table along with other information on the form.- Hide quoted text -

- Show quoted text -

There is more to the code then what i posted. After the values have
been combined the variables are then put into an update query to
update the record we just added with the values.
 
B

BruceM

It is OK to post a fragment of the code as long as it makes sense by itself,
or you explain what happens in the code you did not include.

As I said, you should concatenate the values as needed, but not store the
combined value. You are already storing all of the information you need to
get the combined number.

Again, what happens when you try to compile the code? Where does the
compiling fail?



What happens when you try to compile the code? Where does the compiling
fail?

What is the point of assigning a variable to a string variable in the
command button code? You have not done anything with the variable, and its
value is lost as soon as the cmdSave code has run.

You should just combine the values as needed. As the Control Source of an
unbound text box you could have:
=[cboRCN] & [cboRCN_QUAL]
You could use a similar expression in a calculated column in a query:
NewValue: =[RCN] & [RCN_QUAL]
This assumes RCN and RCN_QUAL are fields in the query's record source.

This expression, or any VBA code that does not specify a combo box column,
uses the values from the combo box bound columns (specified on the
property
sheet for the combo boxes).




I have a form with several combo boxes on it that need to combine into
one value.
cboRCN: selects from a set of unique numbers that code job titles
cboRCN_Qual: selects from a set of unique numbers that code payranges
if cboRCN = 6300 and cboRCN_Qual = 7, I would need to combine these
values to make 63007 ( the code that that particular job/payrange.
I can do this via:
Private Sub cmdSAVE_Click
dim A_RATE as string, D_RATE as string
A_RATE = (me.RCN & me.RCN_QUAL)
end sub
now, here is where my problem arises, when i try to run the code i get
an error saying that the module cannot be compiled.
This is a data entry form only, and is not used to "browse" records.
Is there a different procedure for dealing with these types of forms?
My next problem after that is solved is then putting this value into a
table along with other information on the form.- Hide quoted text -

- Show quoted text -

There is more to the code then what i posted. After the values have
been combined the variables are then put into an update query to
update the record we just added with the values.
 
M

martinmike2

ok, sorry about that.

It compiles fine, it appears I mispoke.

The error I am recieveing is:

Object or Class does not support the set of events.
 
B

BruceM

When do you receive the error? Is it when clicking cmdSave? If so, post
all of the code in cmdSave, and identify the line on which the code fails.

Add the following line to the top of your form's code module, directly under
Option Compare Database:
Option Explicit

Compile the code again. Any undeclared variables will cause a compile
error.

Are you familiar with stepping through code? If not, see below.

Are you using error handling? If not, try something like this in your
procedures:

Private Sub cmdSAVE_Click

On Error GoTo ProcErr

Dim A_RATE as string, D_RATE as string
A_RATE = (me.RCN & me.RCN_QUAL)

ProcExit:
Exit Sub

ProcErr:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") " & _
"in cmdSave"
Resume ProcExit

End Sub

Stepping through the code: In the VBA editor, click the vertical bar to the
left of:
A_RATE = (me.RCN & me.RCN_QUAL)
This adds a dot to the bar, and highlights the line of code. Go to the
form, and run the code by clicking the command button. When the code
reaches the highlighted line (the break point) you will see the code window.
Press the F8 key to step through the code one line at a time. This,
combined with error handling and forcing variable declaration, will allow
you to see just which line of code is causing the problem

The thing that's needed here is to identify just where you are having
problems.

Another thing that could be going on is some corruption. In that case you
can decompile the database, import everything into a new database, and get a
clean start. Allen Browne explains the process here:
http://allenbrowne.com/recover.html

Poke around on Allen's site while you're there. There is a wealth of
information and links.
 
M

martinmike2

I would love to tell you where it is failing in the code, but the
error does not trigger the debugger for the forms module. I tried
stepping through the code but the error dosn't open the editor to
debug the code.

As of right now, the only code in the sub is what i posted above. I
have removed all the other code and still recieve the error, which
leads me to believe that the problem is in the giving of the value to
the variable.

yes, i recieve the error when i click on cmdSave
 
B

BruceM

Please review my suggestions about how to locate the problem. Let me know
what happens for each suggestion.

I don't know what you mean by "the debugger for the forms module". Error
handling as I have described is code that you add to procedures.

Do I understand correctly that this is the only code you have in the form's
code module?
dim A_RATE as string, D_RATE as string
A_RATE = (me.RCN & me.RCN_QUAL)

In that case, place the break point on the only line of code as I described,
and run the code.
 
M

martinmike2

I dont think you understood me earlier.

I can't step through the code because of the following sequence of
events:

1: Press cmdSave
2: The error described above displays
3: Press "OK" ok error window
4: Nothing happens


The code editor does not open in debug mode. It does nothing. When I
manually open the editor after the error, there is nothing to tell me
where the error occured. The break point is still there, but nothing
has changed (broken code not highlighted yellow).

Error handling wont do anything at this juncture because the code
isn't even running. If it were running, I would have been able to
debug the problem in the first place.
 
B

BruceM

I only know what you have told me. This is the first I have learned you
added a break point and tried stepping through the code. I should also have
suggested you try a Compact and Repair (Tools >> Database Utilities). I
still don't know if you added Option Explicit to the code module. I don't
know if you have tried Allen Browne's recovery sequence.

Get rid of the command button. Add a new one. Add something like this to
its click event:

MsgBox "Click is OK"

If the code runs, introduce new code one line at at time.

Also, if clicking a command button (or running any procedure) leads to a
problem before any of the code runs, try adding the break point to the
Private Sub line. As you step through, point to strings, field names, etc.
to see their values.

If you are having a problem only when you click the button, something is
going wrong in that code, or in actions resulting from that code (such as
attempting to save the record).
 

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