Dear All,

Please Help me out in this matter.

I'm developing a small project, in this i'm uploading my combo box with master data ( i.e. List of Equipment).

What i'm doing is once the user complete entering data in form the data is saved. Now when i reload same form the data is upload in blank fields. Now if user want to update record in combo field, what is happening is the data is not reflected in combo ( Actually data is there in combo). i want same record which is save by user previously is shown in combo box.

Please help me..

Actully i fill up combo at runtime from database.
User select any item from combo (i.e. in my case equipment) and subsequently other record fill up based on the equipment selected by user.

Please see the attached word file.

there are around 244 records. if user wants to update record no 2, when i click update button all the combo gone blank.

I want the the same record in combo (from database) when user click update button.

Thanks and Regards

Please see the attachment.

I send you whole code.


Regards

Attachments
Option Explicit
Dim mobjADOConn As ADODB.Connection
Dim mobjADORst As ADODB.Recordset
Dim mobjADORst1 As ADODB.Recordset
Dim mobjADORst_1 As ADODB.Recordset
Dim mobjADORst_2 As ADODB.Recordset
Dim mobjADORst_3 As ADODB.Recordset
Dim mobjADORst2 As ADODB.Recordset
Dim mobjADORst3 As ADODB.Recordset
Dim mobjADORst5 As ADODB.Recordset
Dim dot As String
Dim l As String
Dim num1 As Integer
Dim num2 As Single
Dim snum As Integer
Private mstrSQL As String
Private mstrSQL1 As String
Private mstrSQL_1 As String
Private mstrSQL_2 As String
Private mstrSQL_3 As String
Private mstrSQL2 As String
Private mstrSQL3 As String
Private mstrSQL5 As String
Private mdblMinAsking As Double
Private mblnUpdatePending As Boolean
Private mstrUpdateType As String
Private mavntUSStates As Variant

Private Sub cmbEqu_Click()
txteqcode = CmbEqCode.List(cmbEqu.ListIndex)
txteqloc = cmbLoc.List(cmbEqu.ListIndex)
End Sub

Private Sub cmbEqu_GotFocus()
On Error GoTo LocalError
Dim blnGotData As Boolean
blnGotData = False
cmbEqu.Clear


Do
'select or reload the data to be displayed:
mstrSQL1 = "select Eq_Code" _
& " , Eq_Name" _
& " , Eq_Location" _
& " from EQ_MASTER" _
& " order by Eq_Code"

Set mobjADORst1 = New ADODB.Recordset
mobjADORst1.CursorLocation = adUseClient
mobjADORst1.Open mstrSQL1, mobjADOConn, adOpenDynamic, adLockOptimistic, adCmdText

If mobjADORst1.EOF Then
   MsgBox "No Record Found."
   
   Exit Sub
Else
    blnGotData = True
End If
Loop Until blnGotData
'load data into the text boxes
Dim cnt As Integer
cnt = 0
While mobjADORst1.EOF = False
    cmbEqu.AddItem mobjADORst1(1).Value
    CmbEqCode.AddItem mobjADORst1(0).Value
    cmbLoc.AddItem mobjADORst1(2).Value
    cnt = cnt + 1
    mobjADORst1.MoveNext
Wend
'txteqcode = CmbEqCode.List(cmbEqu.ListIndex)
'txteqloc = cmbLoc.List(cmbEqu.ListIndex)
'Call PopulateFormFields ''''''''

Exit Sub
LocalError:
MsgBox Err.Number & " - " & Err.Description
End Sub

Private Sub cmbEqu_LostFocus()
txteqcode.Text = CmbEqCode.List(cmbEqu.ListIndex)
txteqloc.Text = cmbLoc.List(cmbEqu.ListIndex)
End Sub

Private Sub cmbProbNature_GotFocus()
On Error GoTo LocalError
Dim blnGotData As Boolean
blnGotData = False
cmbProbNature.Clear

Do
'select or reload the data to be displayed:
mstrSQL2 = "select Prob_Code" _
& " , Prob_Name" _
& " from Prob_MASTER" _
& " order by Prob_Code"

Set mobjADORst2 = New ADODB.Recordset
mobjADORst2.CursorLocation = adUseClient
mobjADORst2.Open mstrSQL2, mobjADOConn, adOpenDynamic, adLockOptimistic, adCmdText

If mobjADORst2.EOF Then
   MsgBox "No Record Found."
   Exit Sub
Else
    blnGotData = True
End If
Loop Until blnGotData
'load data into the text boxes
Dim cnt As Integer
cnt = 0
While mobjADORst2.EOF = False
    cmbProbNature.AddItem mobjADORst2(1).Value
    cnt = cnt + 1
    mobjADORst2.MoveNext
Wend
'txteqcode = CmbEqCode.List(cmbEqu.ListIndex)
'txteqloc = cmbLoc.List(cmbEqu.ListIndex)
'Call PopulateFormFields ''''''''

Exit Sub
LocalError:
MsgBox Err.Number & " - " & Err.Description

End Sub


Private Sub CmbSpareConsum_GotFocus()
On Error GoTo LocalError
Dim blnGotData As Boolean
blnGotData = False
CmbSpareConsum.Clear

Do
'select or reload the data to be displayed:
mstrSQL_3 = "select Spare_code" _
& " , Spare_Desc" _
& " from Spare_Master" _
& " order by Spare_Code"

Set mobjADORst_3 = New ADODB.Recordset
mobjADORst_3.CursorLocation = adUseClient
mobjADORst_3.Open mstrSQL_3, mobjADOConn, adOpenDynamic, adLockOptimistic, adCmdText

If mobjADORst_3.EOF Then
   MsgBox "No Record Found."
   Exit Sub
Else
    blnGotData = True
End If
Loop Until blnGotData
'load data into the text boxes
Dim cnt As Integer
cnt = 0
While mobjADORst_3.EOF = False
    CmbSpareConsum.AddItem mobjADORst_3(1).Value
    cnt = cnt + 1
    mobjADORst_3.MoveNext
Wend
'txteqcode = CmbEqCode.List(cmbEqu.ListIndex)
'txteqloc = cmbLoc.List(cmbEqu.ListIndex)
'Call PopulateFormFields ''''''''

Exit Sub
LocalError:
MsgBox Err.Number & " - " & Err.Description
End Sub

Private Sub CmbTechName_GotFocus()
On Error GoTo LocalError
Dim blnGotData As Boolean
blnGotData = False
CmbTechName.Clear

Do
'select or reload the data to be displayed:
mstrSQL_2 = "select Emp_code" _
& " , Emp_Name" _
& " , Emp_Desg" _
& " from Emp_Master" _
& " order by Emp_Code"

Set mobjADORst_2 = New ADODB.Recordset
mobjADORst_2.CursorLocation = adUseClient
mobjADORst_2.Open mstrSQL_2, mobjADOConn, adOpenDynamic, adLockOptimistic, adCmdText

If mobjADORst_2.EOF Then
   MsgBox "No Record Found."
   Exit Sub
Else
    blnGotData = True
End If
Loop Until blnGotData
'load data into the text boxes
Dim cnt As Integer
cnt = 0
While mobjADORst_2.EOF = False
    CmbTechName.AddItem mobjADORst_2(1).Value
    cnt = cnt + 1
    mobjADORst_2.MoveNext
Wend
'txteqcode = CmbEqCode.List(cmbEqu.ListIndex)
'txteqloc = cmbLoc.List(cmbEqu.ListIndex)
'Call PopulateFormFields ''''''''

Exit Sub
LocalError:
MsgBox Err.Number & " - " & Err.Description

End Sub

Private Sub cmdAdd_Click()
On Error GoTo LocalError
  
txtequp.Visible = False
txtnature.Visible = False
txtspare.Visible = False
txtTechName.Visible = False
'txtReason.Visible = False
DTPintdate.Value = Now
DTPrrdate.Value = Now
DTPwcdate.Value = Now
DTPDate.Value = Now

'clear all the text boxes:
txtHID.Text = ""
cmbEqu.Clear
txteqcode.Text = ""
'MaskEdBox4.Text = ""
cmbProbNature.Clear
txteqloc.Text = ""
'MaskEdBox1.Mask = ""
MaskEdBox1.Text = ""
'MaskEdBox2.Mask = ""
MaskEdBox2.Text = ""
'MaskEdBox3.Mask = ""
MaskEdBox3.Text = ""
txtReason.Text = ""
'CmbReasonBD.Clear
CmbTechName.Clear
CmbSpareConsum.Clear
txtbdhr.Text = ""
txtspare.Text = ""
txtTechName.Text = ""
txtReason.Text = ""
txtRemark.Text = ""

SetFormState True
mstrUpdateType = "A"
lsthid.SetFocus
Exit Sub
LocalError:
MsgBox Err.Number & " - " & Err.Description

End Sub

Private Sub cmdCancel_Click()
    PopulateFormFields
    SetFormState False
    txtReason.Visible = True
    txtTechName.Visible = True
    txtspare.Visible = True
    txtequp.Visible = True
    txtnature.Visible = True
End Sub

Private Sub cmdDelete_Click()
On Error GoTo LocalError
'when the current record is deleted, the current location in the recordset
'is invalid. use the Requery method to re-execute the query and update
'the data.
If MsgBox("Are you sure you want to delete this record?", _
vbYesNo + vbQuestion, _
"Delete") = vbNo Then
Exit Sub
End If
mobjADORst.Delete
mobjADORst.Requery
' reposition to one past the record just deleted
mobjADORst.Find "hid > " & txtHID.Text
' If it was the last record that was deleted, the Find method will
' come back with EOF, in which case we should MoveLast to position
' us to the "new" last record ...
If mobjADORst.EOF Then mobjADORst.MoveLast
'load data into the text boxes:
Call PopulateFormFields
  
Exit Sub
  
LocalError:
'MsgBox Err.Number & " - " & Err.Description
MsgBox "Last recored deleted. Please Click on Add to create new record", vbOKOnly
cmdAdd.SetFocus

End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub cmdMoveFirst_Click()

If mobjADORst.EOF Then
    MsgBox " No Record Find"
    Exit Sub
End If

On Error GoTo LocalError
  
mobjADORst.MoveFirst
Call PopulateFormFields
Exit Sub
LocalError:
MsgBox Err.Number & " - " & Err.Description

End Sub

Private Sub cmdMoveLast_Click()

If mobjADORst.EOF Then
    MsgBox " No Record Find"
    Exit Sub
End If

On Error GoTo LocalError
  
mobjADORst.MoveLast
Call PopulateFormFields
Exit Sub
LocalError:
MsgBox Err.Number & " - " & Err.Description

End Sub

Private Sub cmdMoveNext_Click()

If mobjADORst.EOF Then
    MsgBox " No Record Find"
    Exit Sub
End If

On Error GoTo LocalError
  
mobjADORst.MoveNext
If mobjADORst.EOF Then
Beep
mobjADORst.MoveLast
End If
Call PopulateFormFields
Exit Sub
LocalError:
MsgBox Err.Number & " - " & Err.Description

End Sub

Private Sub cmdMovePrevious_Click()

If mobjADORst.EOF Then
    MsgBox " No Record Find"
    Exit Sub
End If

On Error GoTo LocalError
  
mobjADORst.MovePrevious
If mobjADORst.BOF Then
Beep
mobjADORst.MoveFirst
End If
Call PopulateFormFields
Exit Sub
LocalError:
MsgBox Err.Number & " - " & Err.Description

End Sub

Private Sub cmdSave_Click()

On Error GoTo LocalError
  
If Not ValidateAllFields Then Exit Sub
  
If mstrUpdateType = "A" Then
    mobjADORst.AddNew
Else
' We can just update the fields. No explicit Edit method
' is available or needed.
End If
'save the data to the database:
mobjADORst.Fields("hid_type") = lsthid.Text & ""
mobjADORst.Fields("hid") = txtHID.Text & ""
mobjADORst.Fields("Shift") = LstShift.Text & ""
mobjADORst.Fields("Ent_date") = DTPDate.Value & ""
'mobjADORst.Fields("date") = MaskEdBox4.Text & ""
mobjADORst.Fields("eq_name") = cmbEqu.Text & ""
mobjADORst.Fields("eq_code") = txteqcode.Text & ""
mobjADORst.Fields("location") = txteqloc.Text & ""
mobjADORst.Fields("Prob_natu") = cmbProbNature.Text & ""
mobjADORst.Fields("int_date") = DTPintdate.Value & ""
mobjADORst.Fields("int_time") = MaskEdBox1.Text / 100 & ""
mobjADORst.Fields("req_date") = DTPrrdate.Value & ""
mobjADORst.Fields("req_time") = MaskEdBox2.Text / 100 & ""
mobjADORst.Fields("wrkcom_date") = DTPwcdate.Value & ""
mobjADORst.Fields("wrkcom_time") = MaskEdBox3.Text / 100 & ""
mobjADORst.Fields("brk_hr") = txtbdhr.Text & ""
mobjADORst.Fields("spar_cons") = CmbSpareConsum.Text & ""
mobjADORst.Fields("tech_name") = CmbTechName.Text & ""
mobjADORst.Fields("reason") = txtReason.Text & ""
'mobjADORst.Fields("reason") = CmbReasonBD.Text & ""
mobjADORst.Fields("remark") = txtRemark.Text & ""

mobjADORst.Update
  
If mstrUpdateType = "A" Then
'after the new record is added, the db must be re-queried
'so that the resultset contains the new record:
mobjADORst.Requery
' reposition to the record just added
mobjADORst.Find "hid = " & txtHID.Text & " "
'display status info about the new record
SetRecNum
End If
Reset:
SetFormState False
Exit Sub
Local

it seems to me like the combo boxes in the update button are commented out:

'Combo1.Text = rs.Fields(0)
'cmbEqu.Text = mobjADORst1.Fields(cmbEqu.ListIndex)
'cmbLoc.List (cmbEqu.ListIndex)

Since comments don't actually do anything as far as the program goes, then naturally they wouldn't get populated..... try removing the ' from the beginning of those three lines in the cmdUpdate_Click()

Ya.. actually i wrote this code when doing some R&D.
Nothing is happen if i remove this code.

Re.

Don't remove the code.... remove the ' before the code...
Do you have a sample database that you are working with this...
if you can attach the database (or a sample) with the .zip'd vb project,
I can try to see more clearly what you need.

I mean if i remove comments, nothing is happening.

This article has been dead for over six months. Start a new discussion instead.