VB coding help required

  • Thread starter access practice
  • Start date
A

access practice

I am new to this Board and also to using Access.

I have been trying to build a DB to help with my wife in her job search and
am having difficulty with one of the fields and activities.

I have a form called [Contacts] and in it I have a checkbox field called
[InterviewCheckbox]. What I want to happen is if I check the box that she
has an interview, she would get a message box that says "Congratulations!"
and when she clicks OK it would move the insertion point to a text box below
called [InterviewDate] (which is a date formatted text box with input mask).
A programmer friend helped me with the following code, but it still doesn't
move the insertion point to [InterviewDate].


Private Sub InterviewCheckbox_Click()
If ckbInterviewCheckbox <> 0 Then
MsgBox "Congratulations!, Enter the date!", vbOKOnly, "Interview
Congratulation"
InterviewDate.SetFocus()
End If
End Sub

I have scoured through the previous postings and tried various combinations
but cannot get the cursor to automatically move to the [InterviewDate] text
box.

Any suggestions would be very much appreciated.

Thanks,
Steve

(Win 98SE)
(Access 2000)
 
J

John Spencer

Assuming that you have a control named InterviewDate try changing the code
to

InterviewDate.SetFocus 'No parentheses.

You didn't say what error message you were getting. I assume you were
getting some kind of error.

Is the code line you have red? If so, that is an indication of bad syntax
in the code.
 
A

access practice

Thanks for the response John.

It just doesn't work and maybe the issue is I haven't set up the control
properly. I forgot to take out the parentheses in the Post which I had
already done. The problem is that it just doesn't work. When I check the
[InterviewCheckbox I don't even get the message box up and the cursor just
inserts a checkmark into the checkbox; that's it. If I change the variable
to be "=0" instead of <>0 then the message box comes up and I get a runtime
error 424 message when I click OK.

In my Table called [Contacts] I do have a Field Name of [InterviewDate] which
is a date field. Is that what you mean by "control"? If not, can you tell
me what a control is and how to set it up (if that is not too much to ask)?
As I said I am new to this.....

Thanks so much for you help.

Steve

John said:
Assuming that you have a control named InterviewDate try changing the code
to

InterviewDate.SetFocus 'No parentheses.

You didn't say what error message you were getting. I assume you were
getting some kind of error.

Is the code line you have red? If so, that is an indication of bad syntax
in the code.
I am new to this Board and also to using Access.
[quoted text clipped - 35 lines]
(Win 98SE)
(Access 2000)
 
J

John Spencer

A quick terminology lesson.
Tables have fields
Forms have controls
Controls have a control source property which often references a field in a
table.


You have a checkbox control on your form (Contacts) that is named
InterviewCheckbox (at least the code you posted suggests that). That
checkbox might have a control source named InterviewCheckbox or it might
not.

I would use the After Update event to send the message and move the focus.
Your code refers to InterviewCheckbox in the declaration line of the sub,
but then you have ckbInterviewCheckBox in the code. I'll assume the former.
I've also used Me. before the references to the controls. Me is a short way
of referring to the form or report which contains the code you are working
on.

I would rewrite the code as follows. I am using the After Update event.

Private Sub InterviewCheckbox_AfterUpdate()
If Me.InterviewCheckbox = True Then
MsgBox "Congratulations!, Enter the date!", vbOKOnly, "Interview
Congratulation"
Me.InterviewDate.SetFocus
End If
End Sub

Make sure you have entered [Event Procedure] in the Checkboxes AfterUpdate
property.
 
A

access practice via AccessMonster.com

John, you are brilliant!!

Your terminology backgrounder helped me to understand that I was using the
terms "control" and "control sources" synonymously. When I pasted your code,
I had a bug in it, until I realized that my control is actually named
"Interview_Date" as opposed to the control source of "InterviewDate".

Thank you so much for your help. I have found this an incredibly useful
Discussion Board. I can't wait for my wife to see how the DB works since it
is so difficult to be looking for a job in the first place.

Thanks again, John!
Steve

John said:
A quick terminology lesson.
Tables have fields
Forms have controls
Controls have a control source property which often references a field in a
table.

You have a checkbox control on your form (Contacts) that is named
InterviewCheckbox (at least the code you posted suggests that). That
checkbox might have a control source named InterviewCheckbox or it might
not.

I would use the After Update event to send the message and move the focus.
Your code refers to InterviewCheckbox in the declaration line of the sub,
but then you have ckbInterviewCheckBox in the code. I'll assume the former.
I've also used Me. before the references to the controls. Me is a short way
of referring to the form or report which contains the code you are working
on.

I would rewrite the code as follows. I am using the After Update event.

Private Sub InterviewCheckbox_AfterUpdate()
If Me.InterviewCheckbox = True Then
MsgBox "Congratulations!, Enter the date!", vbOKOnly, "Interview
Congratulation"
Me.InterviewDate.SetFocus
End If
End Sub

Make sure you have entered [Event Procedure] in the Checkboxes AfterUpdate
property.
I am new to this Board and also to using Access.
[quoted text clipped - 35 lines]
(Win 98SE)
(Access 2000)
 
J

John Spencer

Blush! Thanks for feedback.

I'm glad you have solved your problem. And I'm always a bit cautious about
posting elementary information. Some people take offense and get upset with
being told what they "already know".

Best wishes to your wife and you on the job hunt.

access practice via AccessMonster.com said:
John, you are brilliant!!

Your terminology backgrounder helped me to understand that I was using the
terms "control" and "control sources" synonymously. When I pasted your
code,
I had a bug in it, until I realized that my control is actually named
"Interview_Date" as opposed to the control source of "InterviewDate".

Thank you so much for your help. I have found this an incredibly useful
Discussion Board. I can't wait for my wife to see how the DB works since
it
is so difficult to be looking for a job in the first place.

Thanks again, John!
Steve

John said:
A quick terminology lesson.
Tables have fields
Forms have controls
Controls have a control source property which often references a field in
a
table.

You have a checkbox control on your form (Contacts) that is named
InterviewCheckbox (at least the code you posted suggests that). That
checkbox might have a control source named InterviewCheckbox or it might
not.

I would use the After Update event to send the message and move the focus.
Your code refers to InterviewCheckbox in the declaration line of the sub,
but then you have ckbInterviewCheckBox in the code. I'll assume the
former.
I've also used Me. before the references to the controls. Me is a short
way
of referring to the form or report which contains the code you are working
on.

I would rewrite the code as follows. I am using the After Update event.

Private Sub InterviewCheckbox_AfterUpdate()
If Me.InterviewCheckbox = True Then
MsgBox "Congratulations!, Enter the date!", vbOKOnly, "Interview
Congratulation"
Me.InterviewDate.SetFocus
End If
End Sub

Make sure you have entered [Event Procedure] in the Checkboxes AfterUpdate
property.
I am new to this Board and also to using Access.
[quoted text clipped - 35 lines]
(Win 98SE)
(Access 2000)
 

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