Add New Record with some value in form

Akai90

Member
Local time
Tomorrow, 06:50
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.
 
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
 
I have no idea what language the labels are in so I can't determine by the names if you have a problem. But, based on what you said, you have a problem with your design. You should have a table that defines the schools and a table that defines the teachers. The data should not be merged into the same table. Then you would have a main form that shows the school information and a subform where you assign teachers to the school.

I can't tell from your description if the relationship between teachers and schools is m-m. In the US it is because some teachers, like special reading or substitutes work at multiple schools. So, I'm going to link to a m-m sample database so you can see the tables you need. In the case of the many-to-many relationship, you need a third table. This table is frequently called a junction table because it joins the teachers and schools. In the sample db, I show two ways to visualize the m-m. From the tblA point of view, I use a main form with a subform. From the tblB point of view, I use a main form in continuous view with a popup form in continuous view.

 

Users who are viewing this thread

Back
Top Bottom