Hi All
When a userform is loaded then initially a textbox appears asking total number of documents. And then when the user types the number and press tab then the next textboxes appear:
1. Policy no
2. Batch no
3. Document type
4. Document Prov
This Quantity textbox drives the number of iterations per input on the form after SAVE button pressed although policy number and batch number textboxes can be left populated.At each SAVE, the values of document type and Document Prov are loaded into the memory of userform FrmReturn.
The following code will keep on running as I haven't defined how many times it has to run. If there are 5 documents then the code will run 5 times and then after last iteration FrmReturn will be displayed. Can anyone please help me in this?
Private Sub CommandButton1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=J:\ASystem.mdb;"
If ComboBox2.Value = "Original" Then
strsql = "Select Original from tblDocType where DocumentType='" & ComboBox1.Value & "' and PolicyNoRangeBeginsWith='" & Left(TextBox1.Value, 1) & "'"
ElseIf ComboBox2.Value = "Certified Copy" Then
strsql = "Select CertifiedCopy from tblDocType where DocumentType='" & ComboBox1.Value & "' and PolicyNoRangeBeginsWith='" & Left(TextBox1.Value, 1) & "'"
Else
strsql = "Select PhotoCopy from tblDocType where DocumentType='" & ComboBox1.Value & "' and PolicyNoRangeBeginsWith='" & Left(TextBox1.Value, 1) & "'"
End If
Set rs = CreateObject("ADODB.Recordset")
rs.Open strsql, cn
If rs.EOF = True Then
Exit Sub
Else
MsgBox rs.Fields(0).Value
End If
With FrmReturn.Controls("ListBox1")
.AddItem ComboBox1.Value
.List(.ListCount - 1, 1) = ComboBox2.Value
End With
FrmReturn.Controls("textbox23").Value = TextBox1.Value
FrmReturn.Controls("textbox24").Value = TextBox3.Value
ComboBox1.Value = ""
ComboBox2.Value = ""
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
Bookmarks