Add New Record with some value in form

Akai90

Member
Local time
Tomorrow, 06:38
Joined
Feb 8, 2022
Messages
67
hi,

i have button click code get some data when add new record but have some bug when i set all importand fields to Required

here the code
C#:
Private Sub Command41_Click()
Dim namasek As String, kodsek As String, jensek As String, nokpp As String, thndaftar As String

Dim tablesaya As Recordset
Dim dbsaya As Database
Set dbsaya = DBEngine.Workspaces(0).Databases(0)
Set tablesaya = dbsaya.OpenRecordset("tUtama", DB_OPEN_TABLE)
namasek = [Institusi]
kodsek = [KodInstitusi]
jensek = [JenisInstitusi]
nokpp = [No KP]
thndaftar = [tahundaftar]
With tablesaya
.AddNew
![nama] = ".Sila kemaskini nama"
![KodInstitusi] = kodsek
![JenisInstitusi] = jensek
![Institusi] = namasek
![No KP] = "000000000000"
![tahundaftar] = Year(Date)
.Update
End With
DoCmd.Close
End Sub

to using this function i need to disable required field which not good because it will save uncomplete information

is the any code working if i enable required fields ?

thanks
 
You could check out the code from here and see if you can adapt it to your project.

for my understand. it will force the empty textbox be fill right ? without enable table fields required ?
 
for my understand. it will force the empty textbox be fill right ? without enable table fields required ?
No, it's the opposite. The code will force the user to fill the Textbox if it's set as required.
 
No, it's the opposite. The code will force the user to fill the Textbox if it's set as required.
my issue is add button

when i click the add button..

it will ask all required fields. usually when add button it will not ask required right..

it will ask when click the saved data.
 
Either, you need to include ALL required fields when you copy a record or you need to change your method.

WHY are you copying a record? Do you have a design issue? Should the "common" data be stored in a parent table? rather than being duplicated?

It isn't wrong per se to copy a record or even a set of records. For example, one client does estimates but he wants to keep a record of each separate version. So, he wants to copy one estimate and give it a new ID. Then go in and make the changes. In this case, the process involves copying data from three related tables. Estimates--> Items--> accessories.
the most importand data is this
namasek = [Institusi]
kodsek = [KodInstitusi]
jensek = [JenisInstitusi]

i am copy because it use same school

if open 1 school in form
i want to add more teacher, i add new button it will bring same namaschool, schoolkod, schooltype
 

Users who are viewing this thread

Back
Top Bottom