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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Form data source (Recordset?) ADO connection

Status
Not open for further replies.

paulsmoothcurt

Programmer
Dec 11, 2004
2
GB
Hi there,

I have a form, that was bound to a table residing locally whilst developing.

Now the active tables are in SQL server, and I have removed the table locally. The form has been set unbound, and instead I connect to SQL server with the forms open event (code below) using ADO and recordset. I would have preferred recordsource (is it possible without local or linked tables?) but I do not want the tables to be visible. Currently reworking the entire app as an Access project, and will set table security later, but need a certain element of the app working asap. So, I need the recordset(if no choice of recordsource) to work in such a way that it will only add a new record,not edit current ones. The form is set to DataEntry mode, but it still doesnt work?

Also, currently some actions are carried out by queries, can I also code the queries in a module, and set a connection for them to the server? If not, I'm forced to use the app as it is, until the adp is finished?

Code:

Dim Conn As ADODB.connection
Dim rst1 As ADODB.Recordset
Set Conn = New ADODB.connection
Conn.Open "Provider=sqloledb;" & _
"Data Source=SERVER;" & _
"Initial Catalog=DATA;" & _
"Integrated Security=SSPI"

Set rst1 = New ADODB.Recordset
With rst1
Set .ActiveConnection = Conn
.Source = "SELECT * FROM ORDERS WHERE DocumentType=1;"
.LockType = adLockOptimistic
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.Open
.AddNew
End With

Set Me.Recordset = rst1

Any suggestions very gratefully received.

Thanks in advance
 
Try setting the AllowEdits property of the form to No.

I think to use the recordsource property, the tables would need to be linked, but perhaps ask the question in the ADP forum (forum958)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top