Command button disable, VBA Code not working

F

FA

I want to disabled a command button after being clicked on a form. In
my
Form Current Event Procedure i have something like this but its
disabling the command button before even clicking it.

If Me.CurrentRecord Then
Command566.Enabled = False
Else
Command566.Enabled = True
End If

I have a single form and each form shows one record of each field in
the table. I want the user to open that form, click the command button
and after clicking the command button, i want it to be disabled.
If the user come back to the same record, or open the form with the
same record the command button should be disabled. Meaning i want to
permenantly disable the command button after being clicked once for
each record.

How can i do that??

Your help would be greatly appreciated

Moe
 
G

Guest

If what you are saying is that you want the command button enabled only for
new records and once clicked, it becomes disabled, then you need to move the
code to the Current event of the form

If Me.NewRecord Then
Command566.Enabled = True
Else
Command566.Enabled = False
End If

Now, to disable it once it has been enabled, you will have to do that in the
Click event of the command button; however, the trick is you cannot disable a
control that has the focus, so you will have to select another control to set
the focus to before you disable it. So the last code in the event should be:

Me.SomeOtherControl.SefFocus
Me.Command566.Enabled = False
 
F

FA

Thanks Klatuu i tried your suggetion but it didnt work for me but i
tried the following in my Form Current event and it worked just fine.
If IsNull(Me.SYS_CODE) Then
Command566.Enabled = True
Else
Command566.Enabled = False
End If
Actually thats what i wanted, if there is a data in Me.SYS_CODE, i want
the command button to be disabled else it should be enabled.

Also i have got your sample database from your site to do mail merge
and its not working some how. Its opening the MS Word and i have a
test word document in my C: drive but i am not seeing any data in the
MS Word. I want to merge an MS Access Query in MS Word, well what i
actually want is to open a MS Access Report in MS Word but wheni do
that i lose all the format and there is no graphics. so i thought i can
make a template for my report in MS Word and then merge the query
behind the report in my MS Access. I am not a VBA Developer so i tried
to use your code to do so but its not showing any data. I tested your
merge it to word database since it has some records so i tried it from
there but it did show me anything in MS Word.
If you can help, i would really really appreciate it.

Thanks

Moe
 

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