Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help understanding what i wrote please.

Status
Not open for further replies.

unborn

Programmer
Jun 26, 2002
362
US
I got this code workign doing what i want some how. Now i need to know how laugh. Is this using the control on my form? Or is this using the controlless coding? What part of it is reuseable? Can i make this into a bas file and edit it so i can easily add new client? Also if this is controlless how would i use it with my ADODC control or vise versa? Which way is best? Thanks for all your help!!

Code:
Private Sub lblAAddclient_Click()
On Error GoTo errr

Dim mCn As ADODB.Connection
Dim mRs As ADODB.Recordset

Set mCn = New ADODB.Connection
Set mRs = New ADODB.Recordset
mCn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\my work\Programs\clients.mdb"
mRs.Open "Clients", mCn, adOpenKeyset, adLockOptimistic, adCmdTable

With mRs
    .AddNew
    .Fields("CompanyName") = Trim(txtABName)
    .Fields("FirstName") = Trim(txtAFName)
    .Fields("MiddleName") = Trim(txtAMInitial)
    .Fields("LastName") = Trim(txtALName)
    .Fields("StreetAddress") = Trim(txtAStreet)
    .Fields("City") = Trim(txtACity)
    .Fields("StateOrProvince") = Trim(txtAState)
    .Fields("PostalCode") = Trim(txtAZip)
    .Fields("HomePhone") = Trim(txtAHome)
    .Fields("WorkPhone") = Trim(txtAWork)
    .Fields("MobilePhone") = Trim(txtACell)
    .Fields("EmailAddress") = Trim(txtAEmail)
    .Fields("Birthdate") = Trim(Format(Replace(txtABDate, "/", ""), "mm/dd/yyyy"))
    .Fields("DateJoined") = Date
    .Fields("PNotes") = Trim(txtAPNotes)
    .Update
End With

mRs.Close
mCn.Close

txtABName = ""
txtAFName = ""
txtAMInitial = ""
txtALName = ""
txtAStreet = ""
txtACity = ""
txtAState = ""
txtAZip = ""
txtAHome = ""
txtAWork = ""
txtACell = ""
txtAEmail = ""
txtABDate = ""
txtAPNotes = ""


MsgBox "Client was successfully added!", , "Add Client"
Exit Sub

errr:
Call errorpop

End Sub

Running in circles is what I do best!
 
I also just added the code below. How would i make it beable to tell what the CustomerID that is auto generated by db is? So i can add it to the other database. Thanks again!

Code:
Dim cCn As ADODB.Connection
Dim cRs As ADODB.Recordset
Dim cntrct As String

Set cCn = New ADODB.Connection
Set cRs = New ADODB.Recordset
cCn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\my work\Programs\clients.mdb"
cRs.Open "Contracts", cCn, adOpenKeyset, adLockOptimistic, adCmdTable


If optACNone.Value = True Then cntrct = "None"
If optACTitanium.Value = True Then cntrct = "Titanium"
If optACPlatinum.Value = True Then cntrct = "Platinum"
If optACGold.Value = True Then cntrct = "Gold"
If optACSilver.Value = True Then cntrct = "Silver"
If optACBronze.Value = True Then cntrct = "Bronze"



With cRs
    .Fields("CustomerID") = [Dont Know How To Go About Getting This Info]
    .Fields("ContractedPCs") = Trim(txtACPCs)
    .Fields("Contract") = cntrct
    .Fields("ContractCost") = Trim(txtACCost)
    .Fields("ContractDate") = Date
End With

cRs.Close
cCn.Close

Running in circles is what I do best!
 
Think of it as a read only field. You can look at it, but not change it. When you add a new record, once you update it, you should be able to just read the customerid field. Assuming Access works the same way as SQL Server in this regard.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top