A
Amy@Ioline
Hi there:
I have two questions:
Q1:
How do I assign today's date to a field within an event procedure? I tried
Me.fieldname.value = Date(), but it doesn't work.
Q2:
I created an Add Record button on a subform on a tab control. When I click
on it in view mode, I get the error message:
"You can't go to the specified record."
I set up another form just like this one. The only difference is that the
form that works uses a table with an autonumber key field. This table does
not have an autonumber key field. Could that be the problem and, if so, how
do I get around it?
Here's the table structure and code for your information:
............................................................
TABLE: Promo_Log (*indicates key field)
PROMO_ID Number *
ContactID Number * (=the link to the parent form)
Respond_Date Date/Time *
Response Text
.........................................................
FORM: Promo_Form
Option Compare Database
Option Explicit
Private Sub MakeFormReadOnly()
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
Me.BTNAddRecord.Enabled = True
Me.BTNEditRecord.Enabled = True
Me.BTNSaveRecord.Enabled = False
End Sub
Private Sub BTNAddRecord_Click()
On Error GoTo Err_BTNAddRecord_Click
Me.AllowAdditions = True
Me.AllowEdits = True
Me.AllowDeletions = True
DoCmd.GoToRecord , , acNewRec
Me.PROMO_ID.SetFocus
Me.BTNEditRecord.Enabled = False
Me.BTNSaveRecord.Enabled = True
Exit_BTNAddRecord_Click:
Exit Sub
Err_BTNAddRecord_Click:
MsgBox Err.Description
Resume Exit_BTNAddRecord_Click
End Sub
Private Sub BTNSaveRecord_Click()
On Error GoTo Err_BTNSaveRecord_Click
Me.CMB_Response.SetFocus
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MakeFormReadOnly
Exit_BTNSaveRecord_Click:
Exit Sub
Err_BTNSaveRecord_Click:
MsgBox Err.Description
Resume Exit_BTNSaveRecord_Click
End Sub
Private Sub BTNEditRecord_Click()
Me.AllowAdditions = False 'Do not allow new record to be added
Me.AllowEdits = True 'Allow Record to be edited
Me.AllowDeletions = False
CMB_Response.SetFocus 'Move cursor to Organization Name field
Me.BTNEditRecord.Enabled = False
Me.BTNAddRecord.Enabled = False
Me.BTNSaveRecord.Enabled = True
End Sub
Private Sub Form_AfterUpdate()
MakeFormReadOnly 'Prevent Record from being edited
End Sub
Private Sub Form_Current()
MakeFormReadOnly
End Sub
Private Sub BTN_Promo_List_Click()
On Error GoTo Err_BTN_Promo_List_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Promo_List_Form"
stLinkCriteria = "[Promo_ID]=" & Me![PROMO_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_BTN_Promo_List_Click:
Exit Sub
Err_BTN_Promo_List_Click:
MsgBox Err.Description
Resume Exit_BTN_Promo_List_Click
End Sub
Private Sub BTN_View_Promos_Click()
On Error GoTo Err_BTN_View_Promos_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Promo_List_Form"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_BTN_View_Promos_Click:
Exit Sub
Err_BTN_View_Promos_Click:
MsgBox Err.Description
Resume Exit_BTN_View_Promos_Click
End Sub
Thank you.
- Amy
I have two questions:
Q1:
How do I assign today's date to a field within an event procedure? I tried
Me.fieldname.value = Date(), but it doesn't work.
Q2:
I created an Add Record button on a subform on a tab control. When I click
on it in view mode, I get the error message:
"You can't go to the specified record."
I set up another form just like this one. The only difference is that the
form that works uses a table with an autonumber key field. This table does
not have an autonumber key field. Could that be the problem and, if so, how
do I get around it?
Here's the table structure and code for your information:
............................................................
TABLE: Promo_Log (*indicates key field)
PROMO_ID Number *
ContactID Number * (=the link to the parent form)
Respond_Date Date/Time *
Response Text
.........................................................
FORM: Promo_Form
Option Compare Database
Option Explicit
Private Sub MakeFormReadOnly()
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
Me.BTNAddRecord.Enabled = True
Me.BTNEditRecord.Enabled = True
Me.BTNSaveRecord.Enabled = False
End Sub
Private Sub BTNAddRecord_Click()
On Error GoTo Err_BTNAddRecord_Click
Me.AllowAdditions = True
Me.AllowEdits = True
Me.AllowDeletions = True
DoCmd.GoToRecord , , acNewRec
Me.PROMO_ID.SetFocus
Me.BTNEditRecord.Enabled = False
Me.BTNSaveRecord.Enabled = True
Exit_BTNAddRecord_Click:
Exit Sub
Err_BTNAddRecord_Click:
MsgBox Err.Description
Resume Exit_BTNAddRecord_Click
End Sub
Private Sub BTNSaveRecord_Click()
On Error GoTo Err_BTNSaveRecord_Click
Me.CMB_Response.SetFocus
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MakeFormReadOnly
Exit_BTNSaveRecord_Click:
Exit Sub
Err_BTNSaveRecord_Click:
MsgBox Err.Description
Resume Exit_BTNSaveRecord_Click
End Sub
Private Sub BTNEditRecord_Click()
Me.AllowAdditions = False 'Do not allow new record to be added
Me.AllowEdits = True 'Allow Record to be edited
Me.AllowDeletions = False
CMB_Response.SetFocus 'Move cursor to Organization Name field
Me.BTNEditRecord.Enabled = False
Me.BTNAddRecord.Enabled = False
Me.BTNSaveRecord.Enabled = True
End Sub
Private Sub Form_AfterUpdate()
MakeFormReadOnly 'Prevent Record from being edited
End Sub
Private Sub Form_Current()
MakeFormReadOnly
End Sub
Private Sub BTN_Promo_List_Click()
On Error GoTo Err_BTN_Promo_List_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Promo_List_Form"
stLinkCriteria = "[Promo_ID]=" & Me![PROMO_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_BTN_Promo_List_Click:
Exit Sub
Err_BTN_Promo_List_Click:
MsgBox Err.Description
Resume Exit_BTN_Promo_List_Click
End Sub
Private Sub BTN_View_Promos_Click()
On Error GoTo Err_BTN_View_Promos_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Promo_List_Form"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_BTN_View_Promos_Click:
Exit Sub
Err_BTN_View_Promos_Click:
MsgBox Err.Description
Resume Exit_BTN_View_Promos_Click
End Sub
Thank you.
- Amy