Re: What am I doing wrong?
- From: "Jim Y" <j.s.yablonsky@xxxxxxxxxxxxxx>
- Date: Mon, 01 May 2006 19:01:53 GMT
"Jim Y" <j.s.yablonsky@xxxxxxxxxxxxxx> wrote in message
news:PGb5g.20403$eR6.5453@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Additional code leading up to the "Update" routine follows.
My texts are too general in their examples. Because I tried to write a database program before, and
it would lock up after so many uses, I am trying to follow examples from texts. Fortunatley, I am
retired and have the time to experiment. I do need help from other than the texts that I have.
You mentioned that ADO and DAO are very similar. Is it absolutely necessary to have the ADO data
control on a form? I do not like a single display, prefering a Flex Grid to display all of the
records to permit the user to select the desired one from the list.
At this time, the user clicks the icon on the tool bar displaying a list box with the stored company
names (2 right now). Selecting one name by double click, that window closes and the company info
with CompanyID is displayed on FrmMain. To make changes to the displayed company, the same icon
must be clicked and on the FrmSelcetClient, click Update to show FrmEnterClient. This is for the
user to modify displayed company info. When the last item, Third Phone Number, has been entered,
FrmSaveClient gives the user the option to Update or cancel. There are other options and messages
on all of the forms. I didn't bother to show them here.
I know that the recordset gets all of the records availabe to work, but I thought (wrongly) that the
displayed record would be the only record to be affected by the update. I am aware that the Seek
method can be used with indexes. I just do not understand how or where it goes in my routines. I
am guessing Sub LstCompany_DblClick in FrmSelectClient is the area that I should be looking in.
Doesn't this line do the same thing?
Set rstCompany = gdbDrvrExp.OpenRecordset("SELECT * " & _
"FROM tblCompany " & _
"WHERE CompanyID = " & LngID)
Thank you,
Jim Y
FrmMain
(ToolBar selection for display of Company info)
Case Is = "Company"
'##### Enter name/address/phone numbers of Client Company
Dim rstCompany As Recordset
With FrmSelectClient
..Top = 3240 '660 (toolbar) + 2520 (separator) + 60
..Left = (Screen.Width - .Width) / 2
..LstCompany.Clear
End With
Set rstCompany = gdbDrvrExp.OpenRecordset("SELECT CompanyID, " & _
"CompanyName FROM tblCompany WHERE CompanyID > 0 " & _
"ORDER BY CompanyName")
'populate the ListBox (LstCompany)
Do Until rstCompany.EOF
FrmSelectClient.LstCompany.AddItem rstCompany.Fields("CompanyName") & " " & _
"[" & rstCompany.Fields("CompanyID") & "]"
FrmSelectClient.LstCompany.ItemData(FrmSelectClient.LstCompany.NewIndex) =
rstCompany.Fields("CompanyID")
rstCompany.MoveNext
Loop
rstCompany.Close
Set rstCompany = Nothing
FrmSelectClient.Show vbModeless, Me
--------------------------------------------------------------------------------------------------
FrmSelectClient
(ListBox displays company names and CompanyID in LstCompany)
Private Sub CmdUpdate_Click()
Dim strMsg1 As String
Dim strMsg2 As String
Dim strMsg3 As String
<SNIP>
'Prepare for first entry to be Updated
With FrmEnterClient
..Show
..Text1.Width = 3870 '3855 + 15
..Text1.MaxLength = 35
..Text1.Text = FrmMain.Text2(giCntEntry).Text
..Text1.SetFocus
End With
End If
Me.Hide
End Sub
=====
Private Sub LstCompany_DblClick()
Dim rstCompany As Recordset
Dim LngID As Long
Call ClearData
'LstCompany.Clear
LngID = LstCompany.ItemData(LstCompany.ListIndex)
Set rstCompany = gdbDrvrExp.OpenRecordset("SELECT * " & _
"FROM tblCompany " & _
"WHERE CompanyID = " & LngID)
FrmMain.LblCoIDNbr.Caption = rstCompany.Fields("CompanyID")
FrmMain.Text2(0).Text = rstCompany.Fields("CompanyName")
FrmMain.Text2(1).Text = rstCompany.Fields("CoAddress")
Me.Hide
rstCompany.Close
Set rstCompany = Nothing
End Sub
--------------------------------------------------------------------------------------------------
FrmEnterClient
(This form is method of entering all data for display on FrmMain)
Private Sub CmdNext_Click()
<SNIP>
'Third Phone Number
ElseIf giCntEntry = 7 Then 'convert to 3-3-4 phone number
FrmMain.Text2(giCntEntry).Text = Format(Text1.Text, "###-###-####")
<SNIP>
' IF FrmMain.LblCoIDNbr.Caption <> "" then Update
With FrmSaveClient
..Show
..Top = 3240
..Left = (Screen.Width - .Width) / 2
If FrmMain.LblCoIDNbr.Caption = "" Then
strEnterCap7 = strEnterCap1 'Save
Else
strEnterCap7 = strEnterCap6 'Update
End If
<SNIP>
End With
Exit Sub
Else
Exit Sub
End If
giCntEntry = giCntEntry + 1
Exit Sub
--------------------------------------------------------------------------------------------------
FrmSaveClient
(This form determines whether dispayed info is to be Saved or Updated)
Private Sub CmdSaveExit_Click()
<SNIP>
If FrmMain.LblCoIDNbr.Caption = "" Then
Call SaveClient
Else
Call UpdateClient
End If
Me.Hide
--------------------------------------------------------------------------------------------------
============================================
Public Sub UpdateClient()
Dim rstCompany As Recordset
On Error GoTo ErrHandler
Set rstCompany = gdbDrvrExp.OpenRecordset("tblCompany")
Workspaces(0).BeginTrans
rstCompany.Edit
rstCompany.Fields("CompanyName") = FrmMain.Text2(0).Text
rstCompany.Fields("CoAddress") = FrmMain.Text2(1).Text
rstCompany.Fields("CoCity") = FrmMain.Text2(2).Text
rstCompany.Fields("CoState") = FrmMain.Text2(3).Text
rstCompany.Fields("CoZIP") = FrmMain.Text2(4).Text
rstCompany.Fields("CoPhone1") = FrmMain.Text2(5).Text
rstCompany.Fields("CoPhone2") = FrmMain.Text2(6).Text
rstCompany.Fields("CoFAX") = FrmMain.Text2(7).Text
rstCompany.Update
Workspaces(0).CommitTrans
rstCompany.Close
Set rstCompany = Nothing
Exit Sub
.
- Follow-Ups:
- Re: What am I doing wrong?
- From: argusy
- Re: What am I doing wrong?
- References:
- What am I doing wrong?
- From: Jim Y
- What am I doing wrong?
- Prev by Date: Re: What am I doing wrong?
- Next by Date: Re: What am I doing wrong?
- Previous by thread: Re: What am I doing wrong?
- Next by thread: Re: What am I doing wrong?
- Index(es):
Relevant Pages
|