Question Inserting a default value from code

josephbupe

Registered User.
Local time
Today, 18:04
Joined
Jan 31, 2008
Messages
247
I want to insert OfficerID of the officer currently logged in as a default value into the table T_FileCases when they create a new record. Already in the login form I have a field that holds the OfficerID when logged in successfully.

Is it anything close to this?:

Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
If Forms.F_FileCases!txtCaseID.Value >= 1 Then
INSERT INTO T_Cases (OfficerID) values Forms.F_FileCases!txtCaseID;
End If
End Sub
 
Is "T_Cases" the RecordSource of the current form and is the current form named "F_FileCases"?
 
RuralGuy's questions aside (they are relevant to solving this), you can't just write a SQL statement in VBA and have it execute. You need a command to do so, such as:
Code:
DoCmd.RunSQL "INSERT INTO T_Cases.OfficerID SELECT Forms.F_FileCases!txtCaseID;"

But it sounds like what you want is a default value for a form control instead, in which case, use the Default property for the control to insert the value.
 
Last edited:
I read it more that the OP wants to use the currently logged-in officer as the default for this session. But I see no need for any complexity at all. If I've understood correctly, I'd start with:
T_Cases!OfficerID = F_FileCases!txtCaseID
 

Users who are viewing this thread

Back
Top Bottom