R
Ray C
Could anyone help please?
I use an unbound Combo Box as a method of finding records in a table and tha
is currently working fine. I am wanting to enter an item into the "Find Combo
Box" and the search for it with the result that ; if the item is not in the
list, the programe tells the operator so and gives the oportunity to ADD a
new record to the table and include the field entered into the Find Combo
Box. Without going into te reason why, I need to have two fielda in the new
record so that I can then search the table, pull up the new record with the
two fields completed and the remaining fields open for Edit ( insert the new
data)
The code I use to add a new record and enter the two fields that ate
required for the subsequent search is as follows :-
Private Sub cmb_Find_Box_3_NotInList(NewData As String, Response As Integer)
Dim strSQL1 As String, strSQL2 As String, strMessage As String
Dim rsMyRs As Recordset, dbMyDB As Database
Debug.Print "cmb_HeaderSelect2 = "; Cmb_HeaderSelect2
Me.AllowEdits = True: Me.AllowAdditions = True: Me.AllowDeletions = True
Set dbMyDB = CurrentDb
strMessage = "Do you want to Add " & NewData & " to list?"
If Cmb_HeaderSelect2 = 6 Then ' Store
Set rsMyRs = dbMyDB.OpenRecordset("tbl_Store", dbOpenDynaset)
ElseIf Cmb_HeaderSelect2 = 4 Then ' SUPPLIERS
' not written yet for this option
End If
If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
rsMyRs.AddNew
rsMyRs.Fields("StoreName") = NewData
rsMyRs.Fields("StoreType") = cmb_HeaderSelect3
rsMyRs.Update
rsMyRs.Requery
'cmd.CommandText = strSQL1
Else
Exit Sub
End If
rsMyRs.Close: dbMyDB.Close
' At this point a new Record has been added to the Table and contains the
two pieces of information in the relative fields "StoreName" and "StoreType"
I now need to Search the Table for the new Record and set that so I will be
able to "Edit" the blank Fields and store the data relative to the record
that I have just created But the usual rouine that I use to find records will
not find the new record.
Though I have done a Requery of the Recorset earlier, I am thinking that I
need to do a Requery of the Ind Combo Box "cmb_Find_Combo_3". Tried the ones
below but I Just get errors.
' cmb_Find_Box_3.Requery
' DoCmd.Requery "cmb_Find_Box_3"
Me.Box_3.ControlSource = "StoreName" ' Set the Control
Source for Display Box 3
Call AfterUpdate_Process1("StoreName", NewData, 2,
cmb_HeaderSelect3, "0034")
Me.AllowEdits = True: Me.AllowAdditions = False: Me.AllowDeletions = False
End Sub
Is my thinking all wrong here`? Can anyone help please?
thanks RayC
I use an unbound Combo Box as a method of finding records in a table and tha
is currently working fine. I am wanting to enter an item into the "Find Combo
Box" and the search for it with the result that ; if the item is not in the
list, the programe tells the operator so and gives the oportunity to ADD a
new record to the table and include the field entered into the Find Combo
Box. Without going into te reason why, I need to have two fielda in the new
record so that I can then search the table, pull up the new record with the
two fields completed and the remaining fields open for Edit ( insert the new
data)
The code I use to add a new record and enter the two fields that ate
required for the subsequent search is as follows :-
Private Sub cmb_Find_Box_3_NotInList(NewData As String, Response As Integer)
Dim strSQL1 As String, strSQL2 As String, strMessage As String
Dim rsMyRs As Recordset, dbMyDB As Database
Debug.Print "cmb_HeaderSelect2 = "; Cmb_HeaderSelect2
Me.AllowEdits = True: Me.AllowAdditions = True: Me.AllowDeletions = True
Set dbMyDB = CurrentDb
strMessage = "Do you want to Add " & NewData & " to list?"
If Cmb_HeaderSelect2 = 6 Then ' Store
Set rsMyRs = dbMyDB.OpenRecordset("tbl_Store", dbOpenDynaset)
ElseIf Cmb_HeaderSelect2 = 4 Then ' SUPPLIERS
' not written yet for this option
End If
If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
rsMyRs.AddNew
rsMyRs.Fields("StoreName") = NewData
rsMyRs.Fields("StoreType") = cmb_HeaderSelect3
rsMyRs.Update
rsMyRs.Requery
'cmd.CommandText = strSQL1
Else
Exit Sub
End If
rsMyRs.Close: dbMyDB.Close
' At this point a new Record has been added to the Table and contains the
two pieces of information in the relative fields "StoreName" and "StoreType"
I now need to Search the Table for the new Record and set that so I will be
able to "Edit" the blank Fields and store the data relative to the record
that I have just created But the usual rouine that I use to find records will
not find the new record.
Though I have done a Requery of the Recorset earlier, I am thinking that I
need to do a Requery of the Ind Combo Box "cmb_Find_Combo_3". Tried the ones
below but I Just get errors.
' cmb_Find_Box_3.Requery
' DoCmd.Requery "cmb_Find_Box_3"
Me.Box_3.ControlSource = "StoreName" ' Set the Control
Source for Display Box 3
Call AfterUpdate_Process1("StoreName", NewData, 2,
cmb_HeaderSelect3, "0034")
Me.AllowEdits = True: Me.AllowAdditions = False: Me.AllowDeletions = False
End Sub
Is my thinking all wrong here`? Can anyone help please?
thanks RayC