|
 |
access thread: Changing recordset to public
Message #1 by Christopher Mohr <CMohr@b...> on Thu, 24 Jan 2002 09:55:55 -0800
|
|
I have the following code. I was wondering if there is anyway to combine the
open recordset command may as public to reduce the amount of code.
Private Sub cmdAdd_Click()
Dim db As Database
Dim rsCompany As Recordset
Dim intNumber As Integer
Set db = CurrentDb()
Set rsCompany = db.OpenRecordset("Company")
rsCompany.AddNew
intNumber = rsCompany.RecordCount
DoCmd.GoToRecord , , acNewRec
rsCompany("CompanyID") = intNumber + 1
rsCompany("CompanyName") = Me.CompanyName
rsCompany("BillAddress") = Me.BillAddress
rsCompany("ShipAddress") = Me.ShipAddress
rsCompany("PhoneNumber") = Me.PhoneNumber
rsCompany("FaxNumber") = Me.FaxNumber
rsCompany("SalesPersonID") = Me.SalesPerson
rsCompany("WebPage") = Me.WebPage
rsCompany("Notes") = Me.Notes
rsCompany.Update
rsCompany.Close
DoCmd.Close
End Sub
Private Sub cmdAddContact_Click()
Dim db As Database
Dim rsCompany As Recordset
Dim intNumber As Integer
Dim stLinkCriteria As String
Set db = CurrentDb()
Set rsCompany = db.OpenRecordset("Company")
rsCompany.AddNew
intNumber = rsCompany.RecordCount
DoCmd.GoToRecord , , acNewRec
rsCompany("CompanyID") = intNumber + 1
rsCompany("CompanyName") = Me.CompanyName
rsCompany("BillAddress") = Me.BillAddress
rsCompany("ShipAddress") = Me.ShipAddress
rsCompany("PhoneNumber") = Me.PhoneNumber
rsCompany("FaxNumber") = Me.FaxNumber
rsCompany("SalesPersonID") = Me.SalesPerson
rsCompany("WebPage") = Me.WebPage
rsCompany("Notes") = Me.Notes
rsCompany.Update
rsCompany.Close
DoCmd.Close
DoCmd.OpenForm "frmContact", , , stLinkCriteria
End Sub
Christopher Mohr
Sales/Business Development
Bay Advanced Technologies, LLC
Fabricated Materials Division
(xxx) xxx-xxxx
(xxx) xxx-xxxx Fax
cmohr@b...
Message #2 by "John Ruff" <papparuff@c...> on Thu, 24 Jan 2002 11:44:06 -0800
|
|
Yes you can. Here is code, using your data, that will do it. Be sure
to add a reference to Microsoft DAO x.x Object Library (Tools >
References)
1st - create a module and cut and paste the following code:
Public Function InsertData(strCoName As String, strBill_Addr As String,
strShip_Addr As String, _
strPhone As String, strFax As String,
intSalesPerson As Integer, _
strWeb As String, strNotes As String) As Boolean
On Error GoTo InsertDate_ERR
Dim rsCompany As dao.Recordset
Dim intNumber As Integer
Dim stLinkCriteria As String
Set rsCompany = CurrentDb().OpenRecordset("Company")
' If there are records in the table then set
' intNumber to the total records count.
' If there are no records, set intNumber
' to zero.
With rsCompany
If Not .BOF And Not .EOF Then
.MoveLast
intNumber = .RecordCount
.MoveFirst
Else
intNumber = 0
End If
' Add the data from the form to the
' Company table
.AddNew
!CompanyID = intNumber + 1
!CompanyName = strCoName
!billaddress = strBill_Addr
!ShipAddress = strShip_Addr
!phonenumber = strPhone
!faxnumber = strFax
!SalesPersonID = intSalesPerson
!webpage = strWeb
!notes = strNotes
.Update
.Close
End With
' Release resources
Set rsCompany = Nothing
' Set the function to true
InsertData = True
InsertDate_EXIT:
Exit Function
InsertDate_ERR:
' There is an error so set the function to false
InsertData = False
MsgBox Err.Number & " - " & Err.Description
Resume InsertDate_EXIT
End Function
2nd - Change the code in the cmdAdd_Click event to:
' If the records was successfully
' added to the table, go to new record
If InsertData(CompanyName, billaddress, ShipAddress, phonenumber, _
faxnumber, salesperson, webpage, notes) Then
DoCmd.GoToRecord , , acNewRec
End If
3rd - Change the code in the cmdAddContact_Click event to:
' If the records was successfully
' added to the table, go to new record
' and open the Contact form
If InsertData(CompanyName, billaddress, ShipAddress, phonenumber, _
faxnumber, salesperson, webpage, notes) Then
DoCmd.GoToRecord , , acNewRec
DoCmd.OpenForm "frmContact", , , stLinkCriteria
End If
John Ruff - The Eternal Optimist :-)
-----Original Message-----
From: Christopher Mohr [mailto:CMohr@b...]
Sent: Thursday, January 24, 2002 9:56 AM
To: Access
Subject: [access] Changing recordset to public
I have the following code. I was wondering if there is anyway to combine
the open recordset command may as public to reduce the amount of code.
Private Sub cmdAdd_Click()
Dim db As Database
Dim rsCompany As Recordset
Dim intNumber As Integer
Set db = CurrentDb()
Set rsCompany = db.OpenRecordset("Company")
rsCompany.AddNew
intNumber = rsCompany.RecordCount
DoCmd.GoToRecord , , acNewRec
rsCompany("CompanyID") = intNumber + 1
rsCompany("CompanyName") = Me.CompanyName
rsCompany("BillAddress") = Me.BillAddress
rsCompany("ShipAddress") = Me.ShipAddress
rsCompany("PhoneNumber") = Me.PhoneNumber
rsCompany("FaxNumber") = Me.FaxNumber
rsCompany("SalesPersonID") = Me.SalesPerson
rsCompany("WebPage") = Me.WebPage
rsCompany("Notes") = Me.Notes
rsCompany.Update
rsCompany.Close
DoCmd.Close
End Sub
Private Sub cmdAddContact_Click()
Dim db As Database
Dim rsCompany As Recordset
Dim intNumber As Integer
Dim stLinkCriteria As String
Set db = CurrentDb()
Set rsCompany = db.OpenRecordset("Company")
rsCompany.AddNew
intNumber = rsCompany.RecordCount
DoCmd.GoToRecord , , acNewRec
rsCompany("CompanyID") = intNumber + 1
rsCompany("CompanyName") = Me.CompanyName
rsCompany("BillAddress") = Me.BillAddress
rsCompany("ShipAddress") = Me.ShipAddress
rsCompany("PhoneNumber") = Me.PhoneNumber
rsCompany("FaxNumber") = Me.FaxNumber
rsCompany("SalesPersonID") = Me.SalesPerson
rsCompany("WebPage") = Me.WebPage
rsCompany("Notes") = Me.Notes
rsCompany.Update
rsCompany.Close
DoCmd.Close
DoCmd.OpenForm "frmContact", , , stLinkCriteria
End Sub
Christopher Mohr
Sales/Business Development
Bay Advanced Technologies, LLC
Fabricated Materials Division
(xxx) xxx-xxxx
(xxx) xxx-xxxx Fax
cmohr@b...
Message #3 by "Christopher Mohr" <cmohr@b...> on Thu, 24 Jan 2002 21:23:26
|
|
John,
I really appritiate the help. I used the code you have provided
and it works great. The only thing I am having problems with is null
values. I want to allow null values for everything except for the
CompanyName and the SalesPerson fields.
Can you help?
Thanks,
Chris
> Yes you can. Here is code, using your data, that will do it. Be sure
> to add a reference to Microsoft DAO x.x Object Library (Tools >
> References)
>
> 1st - create a module and cut and paste the following code:
>
> Public Function InsertData(strCoName As String, strBill_Addr As String,
> strShip_Addr As String, _
> strPhone As String, strFax As String,
> intSalesPerson As Integer, _
> strWeb As String, strNotes As String) As Boolean
> On Error GoTo InsertDate_ERR
>
> Dim rsCompany As dao.Recordset
> Dim intNumber As Integer
> Dim stLinkCriteria As String
>
> Set rsCompany = CurrentDb().OpenRecordset("Company")
>
> ' If there are records in the table then set
> ' intNumber to the total records count.
> ' If there are no records, set intNumber
> ' to zero.
> With rsCompany
> If Not .BOF And Not .EOF Then
> .MoveLast
> intNumber = .RecordCount
> .MoveFirst
> Else
> intNumber = 0
> End If
>
> ' Add the data from the form to the
> ' Company table
> .AddNew
> !CompanyID = intNumber + 1
> !CompanyName = strCoName
> !billaddress = strBill_Addr
> !ShipAddress = strShip_Addr
> !phonenumber = strPhone
> !faxnumber = strFax
> !SalesPersonID = intSalesPerson
> !webpage = strWeb
> !notes = strNotes
> .Update
> .Close
> End With
>
> ' Release resources
> Set rsCompany = Nothing
>
> ' Set the function to true
> InsertData = True
>
> InsertDate_EXIT:
>
> Exit Function
>
> InsertDate_ERR:
> ' There is an error so set the function to false
> InsertData = False
> MsgBox Err.Number & " - " & Err.Description
> Resume InsertDate_EXIT
> End Function
>
> 2nd - Change the code in the cmdAdd_Click event to:
>
> ' If the records was successfully
> ' added to the table, go to new record
> If InsertData(CompanyName, billaddress, ShipAddress, phonenumber, _
> faxnumber, salesperson, webpage, notes) Then
> DoCmd.GoToRecord , , acNewRec
> End If
>
> 3rd - Change the code in the cmdAddContact_Click event to:
>
> ' If the records was successfully
> ' added to the table, go to new record
> ' and open the Contact form
> If InsertData(CompanyName, billaddress, ShipAddress, phonenumber, _
> faxnumber, salesperson, webpage, notes) Then
> DoCmd.GoToRecord , , acNewRec
> DoCmd.OpenForm "frmContact", , , stLinkCriteria
> End If
>
> John Ruff - The Eternal Optimist :-)
>
>
>
>
>
>
> -----Original Message-----
> From: Christopher Mohr [mailto:CMohr@b...]
> Sent: Thursday, January 24, 2002 9:56 AM
> To: Access
> Subject: [access] Changing recordset to public
>
>
> I have the following code. I was wondering if there is anyway to combine
> the open recordset command may as public to reduce the amount of code.
>
> Private Sub cmdAdd_Click()
>
> Dim db As Database
> Dim rsCompany As Recordset
> Dim intNumber As Integer
>
> Set db = CurrentDb()
> Set rsCompany = db.OpenRecordset("Company")
>
> rsCompany.AddNew
> intNumber = rsCompany.RecordCount
> DoCmd.GoToRecord , , acNewRec
> rsCompany("CompanyID") = intNumber + 1
> rsCompany("CompanyName") = Me.CompanyName
> rsCompany("BillAddress") = Me.BillAddress
> rsCompany("ShipAddress") = Me.ShipAddress
> rsCompany("PhoneNumber") = Me.PhoneNumber
> rsCompany("FaxNumber") = Me.FaxNumber
> rsCompany("SalesPersonID") = Me.SalesPerson
> rsCompany("WebPage") = Me.WebPage
> rsCompany("Notes") = Me.Notes
> rsCompany.Update
> rsCompany.Close
> DoCmd.Close
> End Sub
> Private Sub cmdAddContact_Click()
>
> Dim db As Database
> Dim rsCompany As Recordset
> Dim intNumber As Integer
> Dim stLinkCriteria As String
>
> Set db = CurrentDb()
> Set rsCompany = db.OpenRecordset("Company")
>
> rsCompany.AddNew
> intNumber = rsCompany.RecordCount
> DoCmd.GoToRecord , , acNewRec
> rsCompany("CompanyID") = intNumber + 1
> rsCompany("CompanyName") = Me.CompanyName
> rsCompany("BillAddress") = Me.BillAddress
> rsCompany("ShipAddress") = Me.ShipAddress
> rsCompany("PhoneNumber") = Me.PhoneNumber
> rsCompany("FaxNumber") = Me.FaxNumber
> rsCompany("SalesPersonID") = Me.SalesPerson
> rsCompany("WebPage") = Me.WebPage
> rsCompany("Notes") = Me.Notes
> rsCompany.Update
> rsCompany.Close
> DoCmd.Close
>
> DoCmd.OpenForm "frmContact", , , stLinkCriteria
>
> End Sub
>
> Christopher Mohr
> Sales/Business Development
> Bay Advanced Technologies, LLC
> Fabricated Materials Division
> (xxx) xxx-xxxx
> (xxx) xxx-xxxx Fax
> cmohr@b...
>
>
>
>
>
Message #4 by "John Ruff" <papparuff@c...> on Thu, 24 Jan 2002 14:01:36 -0800
|
|
Sure, add the following code to the cmdAdd Click event and the
cmdAddContact Click event, before the If statement:
if len(trim(CompanyName))=0 then
msgbox "Please enter a Company Name"
CompanyName.SetFocus
Exit Sub
endif
if len(trim(SalesPerson))=0 then
msgbox "Please enter the name of a Sales Person"
SalesPerson.SetFocus
Exit Sub
endif
John Ruff - The Eternal Optimist :-)
2nd - Change the code in the cmdAdd_Click event to:
>
> ' If the records was successfully
> ' added to the table, go to new record
> If InsertData(CompanyName, billaddress, ShipAddress, phonenumber,
_
> faxnumber, salesperson, webpage, notes) Then
> DoCmd.GoToRecord , , acNewRec
> End If
>
> 3rd - Change the code in the cmdAddContact_Click event to:
>
> ' If the records was successfully
> ' added to the table, go to new record
> ' and open the Contact form
> If InsertData(CompanyName, billaddress, ShipAddress, phonenumber,
_
> faxnumber, salesperson, webpage, notes) Then
> DoCmd.GoToRecord , , acNewRec
> DoCmd.OpenForm "frmContact", , , stLinkCriteria
> End If
-----Original Message-----
From: Christopher Mohr [mailto:cmohr@b...]
Sent: Thursday, January 24, 2002 9:23 PM
To: Access
Subject: [access] RE: Changing recordset to public
John,
I really appritiate the help. I used the code you have provided
and it works great. The only thing I am having problems with is null
values. I want to allow null values for everything except for the
CompanyName and the SalesPerson fields.
Can you help?
Thanks,
Chris
> Yes you can. Here is code, using your data, that will do it. Be sure
> to add a reference to Microsoft DAO x.x Object Library (Tools >
> References)
>
> 1st - create a module and cut and paste the following code:
>
> Public Function InsertData(strCoName As String, strBill_Addr As
> String, strShip_Addr As String, _
> strPhone As String, strFax As String,
> intSalesPerson As Integer, _
> strWeb As String, strNotes As String) As
> Boolean On Error GoTo InsertDate_ERR
>
> Dim rsCompany As dao.Recordset
> Dim intNumber As Integer
> Dim stLinkCriteria As String
>
> Set rsCompany = CurrentDb().OpenRecordset("Company")
>
> ' If there are records in the table then set
> ' intNumber to the total records count.
> ' If there are no records, set intNumber
> ' to zero.
> With rsCompany
> If Not .BOF And Not .EOF Then
> .MoveLast
> intNumber = .RecordCount
> .MoveFirst
> Else
> intNumber = 0
> End If
>
> ' Add the data from the form to the
> ' Company table
> .AddNew
> !CompanyID = intNumber + 1
> !CompanyName = strCoName
> !billaddress = strBill_Addr
> !ShipAddress = strShip_Addr
> !phonenumber = strPhone
> !faxnumber = strFax
> !SalesPersonID = intSalesPerson
> !webpage = strWeb
> !notes = strNotes
> .Update
> .Close
> End With
>
> ' Release resources
> Set rsCompany = Nothing
>
> ' Set the function to true
> InsertData = True
>
> InsertDate_EXIT:
>
> Exit Function
>
> InsertDate_ERR:
> ' There is an error so set the function to false
> InsertData = False
> MsgBox Err.Number & " - " & Err.Description
> Resume InsertDate_EXIT
> End Function
>
> 2nd - Change the code in the cmdAdd_Click event to:
>
> ' If the records was successfully
> ' added to the table, go to new record
> If InsertData(CompanyName, billaddress, ShipAddress, phonenumber,
_
> faxnumber, salesperson, webpage, notes) Then
> DoCmd.GoToRecord , , acNewRec
> End If
>
> 3rd - Change the code in the cmdAddContact_Click event to:
>
> ' If the records was successfully
> ' added to the table, go to new record
> ' and open the Contact form
> If InsertData(CompanyName, billaddress, ShipAddress, phonenumber,
_
> faxnumber, salesperson, webpage, notes) Then
> DoCmd.GoToRecord , , acNewRec
> DoCmd.OpenForm "frmContact", , , stLinkCriteria
> End If
>
> John Ruff - The Eternal Optimist :-)
>
>
>
>
>
>
> -----Original Message-----
> From: Christopher Mohr [mailto:CMohr@b...]
> Sent: Thursday, January 24, 2002 9:56 AM
> To: Access
> Subject: [access] Changing recordset to public
>
>
> I have the following code. I was wondering if there is anyway to
> combine the open recordset command may as public to reduce the amount
> of code.
>
> Private Sub cmdAdd_Click()
>
> Dim db As Database
> Dim rsCompany As Recordset
> Dim intNumber As Integer
>
> Set db = CurrentDb()
> Set rsCompany = db.OpenRecordset("Company")
>
> rsCompany.AddNew
> intNumber = rsCompany.RecordCount
> DoCmd.GoToRecord , , acNewRec
> rsCompany("CompanyID") = intNumber + 1
> rsCompany("CompanyName") = Me.CompanyName
> rsCompany("BillAddress") = Me.BillAddress
> rsCompany("ShipAddress") = Me.ShipAddress
> rsCompany("PhoneNumber") = Me.PhoneNumber
> rsCompany("FaxNumber") = Me.FaxNumber
> rsCompany("SalesPersonID") = Me.SalesPerson
> rsCompany("WebPage") = Me.WebPage
> rsCompany("Notes") = Me.Notes
> rsCompany.Update
> rsCompany.Close
> DoCmd.Close
> End Sub
> Private Sub cmdAddContact_Click()
>
> Dim db As Database
> Dim rsCompany As Recordset
> Dim intNumber As Integer
> Dim stLinkCriteria As String
>
> Set db = CurrentDb()
> Set rsCompany = db.OpenRecordset("Company")
>
> rsCompany.AddNew
> intNumber = rsCompany.RecordCount
> DoCmd.GoToRecord , , acNewRec
> rsCompany("CompanyID") = intNumber + 1
> rsCompany("CompanyName") = Me.CompanyName
> rsCompany("BillAddress") = Me.BillAddress
> rsCompany("ShipAddress") = Me.ShipAddress
> rsCompany("PhoneNumber") = Me.PhoneNumber
> rsCompany("FaxNumber") = Me.FaxNumber
> rsCompany("SalesPersonID") = Me.SalesPerson
> rsCompany("WebPage") = Me.WebPage
> rsCompany("Notes") = Me.Notes
> rsCompany.Update
> rsCompany.Close
> DoCmd.Close
>
> DoCmd.OpenForm "frmContact", , , stLinkCriteria
>
> End Sub
>
> Christopher Mohr
> Sales/Business Development
> Bay Advanced Technologies, LLC
> Fabricated Materials Division
> (xxx) xxx-xxxx
> (xxx) xxx-xxxx Fax
> cmohr@b...
>
>
$subst('Email.Unsub').
>
>
>
Message #5 by "Christopher Mohr" <cmohr@b...> on Thu, 24 Jan 2002 23:15:56
|
|
John,
I am getting a run time error # 94 invalid use of null.
This is the same error message I was getting before I added the if
statement. I think the code you have supplied requires a not null value.
I am very new to programming. Any assistance is greatly appriciated.
Thanks,
Chris
> Sure, add the following code to the cmdAdd Click event and the
> cmdAddContact Click event, before the If statement:
>
> if len(trim(CompanyName))=0 then
> msgbox "Please enter a Company Name"
> CompanyName.SetFocus
> Exit Sub
> endif
>
> if len(trim(SalesPerson))=0 then
> msgbox "Please enter the name of a Sales Person"
> SalesPerson.SetFocus
> Exit Sub
> endif
>
> John Ruff - The Eternal Optimist :-)
>
>
>
>
> 2nd - Change the code in the cmdAdd_Click event to:
> >
> > ' If the records was successfully
> > ' added to the table, go to new record
> > If InsertData(CompanyName, billaddress, ShipAddress, phonenumber,
> _
> > faxnumber, salesperson, webpage, notes) Then
> > DoCmd.GoToRecord , , acNewRec
> > End If
> >
> > 3rd - Change the code in the cmdAddContact_Click event to:
> >
> > ' If the records was successfully
> > ' added to the table, go to new record
> > ' and open the Contact form
> > If InsertData(CompanyName, billaddress, ShipAddress, phonenumber,
> _
> > faxnumber, salesperson, webpage, notes) Then
> > DoCmd.GoToRecord , , acNewRec
> > DoCmd.OpenForm "frmContact", , , stLinkCriteria
> > End If
>
> -----Original Message-----
> From: Christopher Mohr [mailto:cmohr@b...]
> Sent: Thursday, January 24, 2002 9:23 PM
> To: Access
> Subject: [access] RE: Changing recordset to public
>
>
> John,
>
> I really appritiate the help. I used the code you have provided
> and it works great. The only thing I am having problems with is null
> values. I want to allow null values for everything except for the
> CompanyName and the SalesPerson fields.
>
> Can you help?
>
> Thanks,
>
> Chris
>
> > Yes you can. Here is code, using your data, that will do it. Be sure
>
> > to add a reference to Microsoft DAO x.x Object Library (Tools >
> > References)
> >
> > 1st - create a module and cut and paste the following code:
> >
> > Public Function InsertData(strCoName As String, strBill_Addr As
> > String, strShip_Addr As String, _
> > strPhone As String, strFax As String,
> > intSalesPerson As Integer, _
> > strWeb As String, strNotes As String) As
> > Boolean On Error GoTo InsertDate_ERR
> >
> > Dim rsCompany As dao.Recordset
> > Dim intNumber As Integer
> > Dim stLinkCriteria As String
> >
> > Set rsCompany = CurrentDb().OpenRecordset("Company")
> >
> > ' If there are records in the table then set
> > ' intNumber to the total records count.
> > ' If there are no records, set intNumber
> > ' to zero.
> > With rsCompany
> > If Not .BOF And Not .EOF Then
> > .MoveLast
> > intNumber = .RecordCount
> > .MoveFirst
> > Else
> > intNumber = 0
> > End If
> >
> > ' Add the data from the form to the
> > ' Company table
> > .AddNew
> > !CompanyID = intNumber + 1
> > !CompanyName = strCoName
> > !billaddress = strBill_Addr
> > !ShipAddress = strShip_Addr
> > !phonenumber = strPhone
> > !faxnumber = strFax
> > !SalesPersonID = intSalesPerson
> > !webpage = strWeb
> > !notes = strNotes
> > .Update
> > .Close
> > End With
> >
> > ' Release resources
> > Set rsCompany = Nothing
> >
> > ' Set the function to true
> > InsertData = True
> >
> > InsertDate_EXIT:
> >
> > Exit Function
> >
> > InsertDate_ERR:
> > ' There is an error so set the function to false
> > InsertData = False
> > MsgBox Err.Number & " - " & Err.Description
> > Resume InsertDate_EXIT
> > End Function
> >
> > 2nd - Change the code in the cmdAdd_Click event to:
> >
> > ' If the records was successfully
> > ' added to the table, go to new record
> > If InsertData(CompanyName, billaddress, ShipAddress, phonenumber,
> _
> > faxnumber, salesperson, webpage, notes) Then
> > DoCmd.GoToRecord , , acNewRec
> > End If
> >
> > 3rd - Change the code in the cmdAddContact_Click event to:
> >
> > ' If the records was successfully
> > ' added to the table, go to new record
> > ' and open the Contact form
> > If InsertData(CompanyName, billaddress, ShipAddress, phonenumber,
> _
> > faxnumber, salesperson, webpage, notes) Then
> > DoCmd.GoToRecord , , acNewRec
> > DoCmd.OpenForm "frmContact", , , stLinkCriteria
> > End If
> >
> > John Ruff - The Eternal Optimist :-)
> >
> >
> >
> >
> >
> >
> > -----Original Message-----
> > From: Christopher Mohr [mailto:CMohr@b...]
> > Sent: Thursday, January 24, 2002 9:56 AM
> > To: Access
> > Subject: [access] Changing recordset to public
> >
> >
> > I have the following code. I was wondering if there is anyway to
> > combine the open recordset command may as public to reduce the amount
> > of code.
> >
> > Private Sub cmdAdd_Click()
> >
> > Dim db As Database
> > Dim rsCompany As Recordset
> > Dim intNumber As Integer
> >
> > Set db = CurrentDb()
> > Set rsCompany = db.OpenRecordset("Company")
> >
> > rsCompany.AddNew
> > intNumber = rsCompany.RecordCount
> > DoCmd.GoToRecord , , acNewRec
> > rsCompany("CompanyID") = intNumber + 1
> > rsCompany("CompanyName") = Me.CompanyName
> > rsCompany("BillAddress") = Me.BillAddress
> > rsCompany("ShipAddress") = Me.ShipAddress
> > rsCompany("PhoneNumber") = Me.PhoneNumber
> > rsCompany("FaxNumber") = Me.FaxNumber
> > rsCompany("SalesPersonID") = Me.SalesPerson
> > rsCompany("WebPage") = Me.WebPage
> > rsCompany("Notes") = Me.Notes
> > rsCompany.Update
> > rsCompany.Close
> > DoCmd.Close
> > End Sub
> > Private Sub cmdAddContact_Click()
> >
> > Dim db As Database
> > Dim rsCompany As Recordset
> > Dim intNumber As Integer
> > Dim stLinkCriteria As String
> >
> > Set db = CurrentDb()
> > Set rsCompany = db.OpenRecordset("Company")
> >
> > rsCompany.AddNew
> > intNumber = rsCompany.RecordCount
> > DoCmd.GoToRecord , , acNewRec
> > rsCompany("CompanyID") = intNumber + 1
> > rsCompany("CompanyName") = Me.CompanyName
> > rsCompany("BillAddress") = Me.BillAddress
> > rsCompany("ShipAddress") = Me.ShipAddress
> > rsCompany("PhoneNumber") = Me.PhoneNumber
> > rsCompany("FaxNumber") = Me.FaxNumber
> > rsCompany("SalesPersonID") = Me.SalesPerson
> > rsCompany("WebPage") = Me.WebPage
> > rsCompany("Notes") = Me.Notes
> > rsCompany.Update
> > rsCompany.Close
> > DoCmd.Close
> >
> > DoCmd.OpenForm "frmContact", , , stLinkCriteria
> >
> > End Sub
> >
> > Christopher Mohr
> > Sales/Business Development
> > Bay Advanced Technologies, LLC
> > Fabricated Materials Division
> > (xxx) xxx-xxxx
> > (xxx) xxx-xxxx Fax
> > cmohr@b...
> >
> >
> $subst('Email.Unsub').
> >
> >
> >
>
>
>
>
Message #6 by "John Ruff" <papparuff@c...> on Thu, 24 Jan 2002 16:36:47 -0800
|
|
Add the following to the InsertData function
if len(trim(strBill_Addr))<>0 then
!billaddress = strBill_Addr
endif
if len(trim(strShip_Addr))<>0 then
!ShipAddress = strShip_Addr
endif
if len(trim(strPhone))<>0 then
!phonenumber = strPhone
endif
if len(trim(strFax))<>0 then
!faxnumber = strFax
endif
if len(trim(strWeb))<>0 then
!webpage = strWeb
endif
if len(trim(strNotes))<>0 then
!notes = strNotes
endif
Also open the table and make sure the Required property for each of
these fields is set to No and that the Allow Zero Length property is set
to Yes.
John Ruff - The Eternal Optimist :-)
-----Original Message-----
From: Christopher Mohr [mailto:cmohr@b...]
Sent: Thursday, January 24, 2002 11:16 PM
To: Access
Subject: [access] RE: Changing recordset to public
John,
I am getting a run time error # 94 invalid use of null. This is
the same error message I was getting before I added the if
statement. I think the code you have supplied requires a not null value.
I am very new to programming. Any assistance is greatly appriciated.
Thanks,
Chris
>
|
|
 |