I have multiple forms and I wish to write to multiple tables from within each form.
The code I use is currently:
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM Assets"
rst.AddNew
rst!EmployeeID = Forms("frmLoanForm"
.txtEmpID.SetFocus
rst!EmployeeID = Forms("frmLoanForm"
.txtEmpID.Text
rst!LoanStartDate = Forms("frmLoanForm"
.txtStartDate.SetFocus
rst!LoanStartDate = Forms("frmLoanForm"
.txtStartDate.Text
rst!LoanEndDate = Forms
etc etc.
Writing lenghty statements like this over and over is excessive and what I am trying to do is pass the parameters
from my form "frmMain" to "Module1".
The function I have within Module1 takes the stucture of
Function dbWrite(tbl as tableDef, frm as Form)
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tbl"
rst.AddNew
rst!EmployeeID = Forms("frm"
.txtEmpID.SetFocus
rst!EmployeeID = Forms("frm"
.txtEmpID.Text
rst!LoanStartDate = Forms("frm"
.txtStartDate.SetFocus
rst!LoanStartDate = Forms("frm"
.txtStartDate.Text
rst!LoanEndDate = Forms
etc..
End Function
The calling function from one of my forms lets say "frmMain"
Private sub Test cmd_Click()
call module1.dbWrite("Assets",frmMain"
End Sub
// This does not work and gives me syntax errors.I think it is the layout or structure of my code.. Any advice would be appreciated. "Assets" is the table I am trying to pass.
--------
Marty..
The code I use is currently:
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM Assets"
rst.AddNew
rst!EmployeeID = Forms("frmLoanForm"
rst!EmployeeID = Forms("frmLoanForm"
rst!LoanStartDate = Forms("frmLoanForm"
rst!LoanStartDate = Forms("frmLoanForm"
rst!LoanEndDate = Forms
etc etc.
Writing lenghty statements like this over and over is excessive and what I am trying to do is pass the parameters
from my form "frmMain" to "Module1".
The function I have within Module1 takes the stucture of
Function dbWrite(tbl as tableDef, frm as Form)
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tbl"
rst.AddNew
rst!EmployeeID = Forms("frm"
rst!EmployeeID = Forms("frm"
rst!LoanStartDate = Forms("frm"
rst!LoanStartDate = Forms("frm"
rst!LoanEndDate = Forms
etc..
End Function
The calling function from one of my forms lets say "frmMain"
Private sub Test cmd_Click()
call module1.dbWrite("Assets",frmMain"
End Sub
// This does not work and gives me syntax errors.I think it is the layout or structure of my code.. Any advice would be appreciated. "Assets" is the table I am trying to pass.
--------
Marty..