Dear experts
I’m bit stuck here. hours and hours of research in web didn’t help me.
The code I wrote to fill text boxes in an access form works but its very slow. It’s really nice if someone can advice me how to optimize the code.
The frmWochenPaln_Main is a bound, continuous form to the qryLayOut. In the form body there are 18 textboxes, those control source are set to the 18 fields of the query.
Screenshot: db.tt/IJmZQJWs
The 18 text boxes in the forms detail area are laid out like this:
txbA1P1RecNr txbA2P1RecNr txbA3P1RecNr txbA4P1RecNr txbA5P1RecNr txbA6P1RecNr
txbA1P2RecNr txbA2P2RecNr txbA3P2RecNr txbA4P2RecNr txbA5P2RecNr txbA6P2RecNr
txbA1P3RecNr txbA2P3RecNr txbA3P3RecNr txbA4P3RecNr txbA5P3RecNr txbA6P3RecNr
In addition to the above 18 textboxes with record numbers, there are 18 blocks of 12 textboxes. Wichich contains Material number, Material description and so on. In these textboxes the control source is a function.
Screenshot db.tt/nKz5Gguk
What I’m trying to achieve is on the opening of the form or on refresh the form code as to go through all the 18 RecNr textboxes till the end of the records (it’s always 6 records) on the continues form. If value found, search this value in the table tblProdPlan_Woche and fill the corresponding textboxes with rest of the field values found for the record in table tblProdPlan.
Screenshot db.tt/VqZ5DFKH
Thank you very much in advance for your comments.
Priyan
The Code:
My Code looks like this:
Public MatBez_x As String
Public db As DAO.Database
Public rs As DAO.Recordset
Public strTextboxName As String
Public pubMatnr, pubMatbez, pubAnzMisch, pubAufGroesZUN, pubBeutelzahl, pubBeutelFormat, pubEinAufMeng, pubInfo1, pubInfo2, pubKartFormat, pubMRDRMisch, pubStartZeit As String
Public Function ConnectionOpen()
Set db = CurrentDb
Set rs = db.OpenRecordset("qryWocheDetailBereich")
End Function
Public Function ConnectionClose()
Set db = Nothing
Set rs = Nothing
End Function
Public Function MatNr(CtlGID As String) As String
ConnectionOpen
' Formname und textfeld
Dim frm As Form
Dim txb As TextBox
strTextboxName = "txb" & CtlGID & "RecordNr"
Set frm = Forms("frmWochenPlan_Main")
Set txb = frm.Controls(strTextboxName)
' Check if there is a record number available in the RecordNr txb
If txb.Value <> "" Then
rs.FindFirst "ProdPlanW_ID = " & txb.Value
MatNr = Nz(rs.Fields("Mat_MRDR_Artikel"), "")
' füllt die public Variabeln ab
pubMatnr = Nz(rs.Fields("Mat_MRDR_Artikel"), "")
pubMatbez = Nz(rs.Fields("Mat_Bez_Kurz"), "")
pubAnzMisch = Nz(rs.Fields("Anzahl_Mischung"), "")
pubAufGroesZUN = Nz(rs.Fields("Auftragsgroesse_ZUN"), "")
pubBeutelzahl = Nz(rs.Fields("Mat_BeutelProZUN"), "")
pubBeutelFormat = Nz(rs.Fields("Mat_BeutelFormat"), "")
pubEinAufMeng = ""
pubInfo1 = Nz(rs.Fields("Mat_Infofled1"), "")
pubInfo2 = Nz(rs.Fields("Infofeld2"), "")
pubKartFormat = Nz(rs.Fields("Mat_Kartonformat"), "")
pubMRDRMisch = Nz(rs.Fields("Mat_MRDR_Mischung_Komp"), "")
pubStartZeit = Nz(rs.Fields("Start_Zeit") & rs.Fields("Start_Tag"), "")
Else
pubMatnr = ""
pubMatbez = ""
pubAnzMisch = ""
pubAufGroesZUN = ""
pubBeutelzahl = ""
pubBeutelFormat = ""
pubEinAufMeng = ""
pubInfo1 = ""
pubInfo2 = ""
pubKartFormat = ""
pubMRDRMisch = ""
pubStartZeit = ""
End If
ConnectionClose
End Function
Public Function MatBez(CtlGID As String) As String
MatBez = pubMatbez
End Function
Public Function EinAufMeng(CtlGID As String) As String
EinAufMeng = pubEinAufMeng
End Function
Public Function Beutelzahl(CtlGID As String) As String
Beutelzahl = pubBeutelzahl
End Function
Public Function StartZeit(CtlGID As String) As String
StartZeit = pubStartZeit
End Function
Public Function Info1(CtlGID As String) As String
Info1 = pubInfo1
End Function
Public Function Info2(CtlGID As String) As String
Info2 = pubInfo2
End Function
Public Function BeutFormat(CtlGID As String) As String
BeutFormat = pubBeutFormat
End Function
Public Function AufGroesZUN(CtlGID As String) As String
AufGroesZUN = pubAufGroesZUN
End Function
Public Function MRDRMisch(CtlGID As String) As String
MRDRMisch = pubMRDRMisch
End Function
Public Function AnzMisch(CtlGID As String) As String
AnzMisch = pubAnzMisch
End Function
Public Function KartFormat(CtlGID As String) As String
KartFormat = pubKartFormat
End Function
I’m bit stuck here. hours and hours of research in web didn’t help me.
The code I wrote to fill text boxes in an access form works but its very slow. It’s really nice if someone can advice me how to optimize the code.
The frmWochenPaln_Main is a bound, continuous form to the qryLayOut. In the form body there are 18 textboxes, those control source are set to the 18 fields of the query.
Screenshot: db.tt/IJmZQJWs
The 18 text boxes in the forms detail area are laid out like this:
txbA1P1RecNr txbA2P1RecNr txbA3P1RecNr txbA4P1RecNr txbA5P1RecNr txbA6P1RecNr
txbA1P2RecNr txbA2P2RecNr txbA3P2RecNr txbA4P2RecNr txbA5P2RecNr txbA6P2RecNr
txbA1P3RecNr txbA2P3RecNr txbA3P3RecNr txbA4P3RecNr txbA5P3RecNr txbA6P3RecNr
In addition to the above 18 textboxes with record numbers, there are 18 blocks of 12 textboxes. Wichich contains Material number, Material description and so on. In these textboxes the control source is a function.
Screenshot db.tt/nKz5Gguk
What I’m trying to achieve is on the opening of the form or on refresh the form code as to go through all the 18 RecNr textboxes till the end of the records (it’s always 6 records) on the continues form. If value found, search this value in the table tblProdPlan_Woche and fill the corresponding textboxes with rest of the field values found for the record in table tblProdPlan.
Screenshot db.tt/VqZ5DFKH
Thank you very much in advance for your comments.
Priyan
The Code:
My Code looks like this:
Public MatBez_x As String
Public db As DAO.Database
Public rs As DAO.Recordset
Public strTextboxName As String
Public pubMatnr, pubMatbez, pubAnzMisch, pubAufGroesZUN, pubBeutelzahl, pubBeutelFormat, pubEinAufMeng, pubInfo1, pubInfo2, pubKartFormat, pubMRDRMisch, pubStartZeit As String
Public Function ConnectionOpen()
Set db = CurrentDb
Set rs = db.OpenRecordset("qryWocheDetailBereich")
End Function
Public Function ConnectionClose()
Set db = Nothing
Set rs = Nothing
End Function
Public Function MatNr(CtlGID As String) As String
ConnectionOpen
' Formname und textfeld
Dim frm As Form
Dim txb As TextBox
strTextboxName = "txb" & CtlGID & "RecordNr"
Set frm = Forms("frmWochenPlan_Main")
Set txb = frm.Controls(strTextboxName)
' Check if there is a record number available in the RecordNr txb
If txb.Value <> "" Then
rs.FindFirst "ProdPlanW_ID = " & txb.Value
MatNr = Nz(rs.Fields("Mat_MRDR_Artikel"), "")
' füllt die public Variabeln ab
pubMatnr = Nz(rs.Fields("Mat_MRDR_Artikel"), "")
pubMatbez = Nz(rs.Fields("Mat_Bez_Kurz"), "")
pubAnzMisch = Nz(rs.Fields("Anzahl_Mischung"), "")
pubAufGroesZUN = Nz(rs.Fields("Auftragsgroesse_ZUN"), "")
pubBeutelzahl = Nz(rs.Fields("Mat_BeutelProZUN"), "")
pubBeutelFormat = Nz(rs.Fields("Mat_BeutelFormat"), "")
pubEinAufMeng = ""
pubInfo1 = Nz(rs.Fields("Mat_Infofled1"), "")
pubInfo2 = Nz(rs.Fields("Infofeld2"), "")
pubKartFormat = Nz(rs.Fields("Mat_Kartonformat"), "")
pubMRDRMisch = Nz(rs.Fields("Mat_MRDR_Mischung_Komp"), "")
pubStartZeit = Nz(rs.Fields("Start_Zeit") & rs.Fields("Start_Tag"), "")
Else
pubMatnr = ""
pubMatbez = ""
pubAnzMisch = ""
pubAufGroesZUN = ""
pubBeutelzahl = ""
pubBeutelFormat = ""
pubEinAufMeng = ""
pubInfo1 = ""
pubInfo2 = ""
pubKartFormat = ""
pubMRDRMisch = ""
pubStartZeit = ""
End If
ConnectionClose
End Function
Public Function MatBez(CtlGID As String) As String
MatBez = pubMatbez
End Function
Public Function EinAufMeng(CtlGID As String) As String
EinAufMeng = pubEinAufMeng
End Function
Public Function Beutelzahl(CtlGID As String) As String
Beutelzahl = pubBeutelzahl
End Function
Public Function StartZeit(CtlGID As String) As String
StartZeit = pubStartZeit
End Function
Public Function Info1(CtlGID As String) As String
Info1 = pubInfo1
End Function
Public Function Info2(CtlGID As String) As String
Info2 = pubInfo2
End Function
Public Function BeutFormat(CtlGID As String) As String
BeutFormat = pubBeutFormat
End Function
Public Function AufGroesZUN(CtlGID As String) As String
AufGroesZUN = pubAufGroesZUN
End Function
Public Function MRDRMisch(CtlGID As String) As String
MRDRMisch = pubMRDRMisch
End Function
Public Function AnzMisch(CtlGID As String) As String
AnzMisch = pubAnzMisch
End Function
Public Function KartFormat(CtlGID As String) As String
KartFormat = pubKartFormat
End Function