دنبال کننده ها

۱۳۹۶ آذر ۱۱, شنبه

vba - Microsoft Access, vbYesNo can't get record to save

[ad_1]



Originally I had a form which would save a record if I in putted details into one text field and selected an unbound combo box that brought back details of all previous records, fixed that. Then I had the same problem on the close button which I also fixed, finally the actual problem now is I've created a vbYesNo on the save record button which ask me if is a new record if it is a yes it saves as a new record, otherwise it doesn't save however it does not update as a new record, please help.



Option Compare Database
Dim currRecord As Integer



Private Sub btnClose_Click()



If Me.Dirty Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdUndo



`If UserAccess = "Contractor" Then`
`DoCmd.Close`
`DoCmd.OpenForm "frmContractorSwitchBoard"`

`Else
DoCmd.Close
DoCmd.OpenForm "frmSwitchBoard"
End If

DoCmd.SetWarnings True
Else
Call checkUser
End If
End Sub

Private Sub btnSaveDetails_Click()

Dim Response As Integer

Response = MsgBox("Do you wish to create a new record?", vbYesNo,
"Continue?")


If IsNull(txtLocation) Then
MsgBox "Please Enter Location Details"
Else
If Response = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord , , acNewRec
Me.Refresh
Me.cboSelectLocation = ""
txtLocation.SetFocus
Else
DoCmd.RunCommand acCmdUndo
End If
End If
End Sub

Private Sub noUpdate()

currRecord = Str(Nz(Screen.ActiveControl))

Me.txtLocation = DLookup("Location", "tblLocation", "LID = " &
currRecord)
Me.txtRoom = DLookup("Room", "tblLocation", "LID = " & currRecord)
Me.chkTafe = DLookup("Tafe", "tblLocation", "LID = " & currRecord)

End Sub

Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
txtLocation.SetFocus
End Sub


'------------------------------------------------------------
' cboSelectLocation_AfterUpdate
'
'------------------------------------------------------------
Private Sub cboSelectLocation_AfterUpdate()
On Error GoTo cboSelectLocation_AfterUpdate_Err
Call noUpdate



'DoCmd.SearchForRecord , "", acFirst, "[LID] = " & 
Str(Nz(Screen.ActiveControl, 0))'

cboSelectLocation_AfterUpdate_Exit:
Exit Sub

cboSelectLocation_AfterUpdate_Err:
MsgBox Error$
Resume cboSelectLocation_AfterUpdate_Exit

End Sub



[ad_2]

لینک منبع