On Mon, 21 Feb 2005 12:38:27 -0330, Tim Marshall
<TI****@PurpleP andaChasers.Moe rtherium> wrote:
.....
Seriously though, how would you do it?
The following is not tested, but it should give you the idea...
Private Sub btnOk_Click()
'This will run an insert/update for the main TBL_ACTION and a
'series of INSERTS for TBL_ACTION_TERR AIN if this is a new
'record. If an old record, a delete of existing
'TBL_ACTION_TER RAIN will occur first
Dim lngPk As Long
Dim strInvalidDataM sg As String
Dim ctlInvalidEntry As Access.Control
On Error GoTo Err_Proc
If Not IsDataValid(str InvalidDataMsg, ctlInvalidEntry ) Then
Exit Sub
End If
lngPk = GetPrimaryKey()
fRestrictions lngPk
Forms!frmsetup. subExplain.Form .Requery
ResyncSubExplai nBookmark lngPk
DoCmd.Close acForm, "frmsetupAction sadd", acSaveNo
Exit_Proc:
Exit Sub
Err_Proc:
Select Case Err.Number
Case 3022 'index - in this case, a repaeated name
MsgBox "You already have an action with the " & _
"abbreviati on """ & Me.txtAbrev & """", _
vbExclamation
Me.txtName.SetF ocus
Case Else
MsgBox "Error " & Err.Number & " " & Err.Description , _
vbCritical, _
"frmSetUpAction sAdd btnOk_Click", _
Err.HelpFile, Err.HelpContext
End Select
Resume Exit_Proc
End Sub
Private Function IsBlankEntry(va rEntry As Variant) As Boolean
IsBlankEntry = (Len(Trim(varEn try & ""))=0)
End Function
Private Function IsDataValid( _
ByRef strInvalidDataM sg As String, _
ByRef ctlInvalidEntry As Access.Control _
) As Boolean
Dim blnResultOk As Boolean
Dim intC As Integer
Dim lngPk As Long
If IsBlankEntry(Me .txtAbrev) Then
blnResultOk = False
strInvalidDataM sg = "Enter a unique (for this campaign" & _
") abbreviation/code for this action!"
Set ctlInvalidEntry = Me.txtAbrev
ElseIf IsBlankEntry(Me .txtName) Then
blnResultOk = False
strInvalidDataM sg = "Enter a name for this action!"
Set ctlInvalidEntry = Me.txtName
ElseIf Nz(Me.fraType, 0) = 0 Then
blnResultOk = False
strInvalidDataM sg = "You haven't chosen an action type."
Set ctlInvalidEntry = Me.fraType
ElseIf fCheckDest = False Then
blnResultOk = False 'a separate procedure
ElseIf fSelectTerrain = False
blnResultOk = False
ElseIf Me.fraType = 11 Or Me.fraType = 12 Then
lngPk = 0
For intC = 0 To Me.lstDestinati on.ListCount - 1
If Me.lstDestinati on.Selected(int C) Then
lngPk = Me.lstDestinati on.Column(0, intC)
Exit For
End If
Next intC
If lngPk = 0 Then 'nothing chosen
blnResultOk = False
strInvalidDataM sg = "Choose a terrain type ""effect""" & _
" for the crossing/obstacle!"
Set ctlInvalidEntry = Me.lstDestinati on
End If
ElseIf Me.txtValue.Ena bled = True And _
IsNull(Me.txtVa lue) _
Then
strInvalidDataM sg = "Enter a value!"
Set ctlInvalidEntry = Me.txtValue
ElseIf Me.txtMissions. Enabled = True And _
IsNull(Me.txtMi ssions) _
Then
strInvalidDataM sg = "Enter number of missions!"
Set ctlInvalidEntry = Me.txtMissions. SetFocus
End If
IsDataValid = blnResultOk
End Function
Private Function GetPrimaryKey() As Long
Dim lngPk As Long
Select Case Forms!frmsetup. subExplain.Form .txtAddEdit
Case "add"
strSql = fInsert Else strSql = fUpdate
Case "edit"
lngPk = Forms!frmsetup. subExplain.Form .ACT_PK
Case Else
lngPk = DMax("ACT_PK", "TBL_ACTION S", _
"ACT_GAM_FK = " & Forms!frmsetup. txtPK)
End Select
GetPrimaryKey = lngPk
End Function
Private Sub ResyncSubExplai nBookmark(lngPk As Long)
Dim rst As DAO.Recordset
Set rst = Forms!frmsetup. subExplain.Form .RecordsetClone
With rst
.MoveFirst
.FindFirst "ACT_PK = " & lngPk
Forms!frmsetup. subExplain.Form .Bookmark = .Bookmark
.MoveFirst
' Don't .Close it if you didn't .Open it
'.Close < Don't do this.
End With
Set rst = Nothing
End Sub