Command Button VB Coding

G

Guest

I have a form linked to a table. I have designed the form to accept entries,
edits and deletions. I have several questions in relation to command
buttons. Table fields are:
IDNo - Autonumber - primary key
RegisterNumber - Text - uses Me.NewRecord to create new number - primary key
DeptCode - Text - Table lookup using combo box
Designation - Text - Table lookup using combo box
DateSent - Date - =Date()
SentTo - Text
CompanyName(s) - Text
CopiedTo - Text
Subject - Text
Hyperlink1 - Hyperlink
Hyperlink2 - Hyperlink
Hyperlink3 - Hyperlink
UserName - Text - Captures user name using =fOSUserName()
UpdateLog - Text - Display audit log information if available
Reason(s)forEdit - Text
DeleteDate - Date - =Date()
DeptReqDel - Text - Table lookup using combo box
ReasonforDel - Text
PersonReqDel - Text - Captures user name using =fOSUserName()

Q1. I have three buttons; add new record, edit record, delete record. I
would like to place VB code behind these buttons to grey out certain fields
and NOT allow data entry/change depending on which button is selected e.g. if
add new record is selected I would like the control fields 'reasonsforedit',
reasonfordel, deletedate, deptreqdel, personreqdel etc..to be greyed out and
disabled.

Q2. I would also like to be able to validate fields with VB Code dependent
on whether it is entry, edit or delete to ensure that all data required has
been entered.

Q3. I have also have a print button to print the current recordset, using
the code provided by Allan Browne. How can I code to print the correct
report 'entry report' or 'edit report' or 'delete report'?

For information I am also using the audit log created by Alan Browne.

I would appreciate it if anyone could please help me as I understand very
little VB coding. I have tried using conditional formatting but could not
get the box to grey out.
 
E

Ed Robichaud

You can set your controls' Visible or Enabled properties to True/False
depending on which cmdbutton is used. Similarly, you could check the values
of ReasonforEdit and DeleteDate in the control source of your reports'
title. Make your report title an unbound text field and set its control
source to something like:
=IIF(Isnull(Forms!myForm!ReasonforEdit) AND
Isnull(Forms!myForm!DeleteDate) "Entry Report",.....etc.

BTW, you should probably move the hyperlink1,2,3 fields to a related table.
-Ed
 
G

Guest

Thank you Ed for your assistance but please forgive this newbie for asking a
silly question; If I change the visible and enabled properties of the
reasonsforedit control to True/False on what event do I code the addnewrec
command button to active those properties and what would the code be. Many
thanks
 
E

Ed Robichaud

Sue-
An example: you would use the OnClick event of your "Add New Record" button
to reset the properties of those controls that you changed with your "Edit
Record" button. Something like:

DoCmd.GoToRecord , , A_NEWREC
'grey out the "Edit Record" button
Me!btnEditRecord.Enabled = False
'hide the "deletedate" textbox
Me!deletedate.Visible = False
'etc.

-Ed
 

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