473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Problems with Access Front End to SQL Server Tables

I have an Access application for which I'm trying to put the data on SQL Server. The data got there fine, but I'm having a problem running the application.

The application is a membership enrollment application. The scripts behind some forms (buttons) crash when they attempt to add a new record to a table. The command line is "DoCmd.GoToRecord , , acNewRec"

Can someone suggest a different approach for adding a new record?

Does anyone have other advice about problems I'm likely to encounter?

Thanks,


Dante
Mar 20 '09 #1
6 5283
missinglinq
3,532 Expert 2GB
Does the line

"DoCmd.GoToRecord , , acNewRec"

actually have the quotation marks around it in code, or did you just add that for emphasis here?

Also, define "crash." Did the db actually crash or is there an error message?

Linq ;0)>
Mar 20 '09 #2
You might want to check to see if it's a permissions issues. Does the account you're logged in as have write access to the SQL server?

I've always found it easier to link the SQL table to your Access program, then make a connection to it using CurrentProject.Connection and modify it as if it were a 'local' table.
Mar 20 '09 #3
Linq

1: The quotes are not in the code
2: The crash is an error message: "Run-Time Error 2105. You can't go to the specified record.

DBrother
Can you give me any insight about how to find the CurrentProject.Connection? It sounds like exactly what I'm looking for.


Dante
Mar 20 '09 #4
Firstly, are you sure it's not a permissions issue? The error " you can't go to the specified record" seems like you can't create a new record, which means you don't have access.

You will have to do a good bit of research on ADODB recordsets and connections to do exactly what you want to do, but I will provide some coding of such an example. The process below goes as follows:

1) Just getting a formatted date string (no relevance)
2) I know that I will be using 2 different recordsets here, 1 to check a local temp data table and one with the SQL server data
3) strSQLSN is a variable of a SQL string that runs a query on the SQL table
4) I open the SQL (remote) recordset and run the query from strSQLSN
5) It checks the table for a duplicate, gives error if true, and resets.
6) Close and reopen the recordset and check to see if we have an active connection to the DB (network is active) if not, store data in temp table.
7) If so, check temp table for data and upload records into SQL table if temp records exist.
8) Close connections and empty recordsets when you are through with them.
9) Just updating a table (no relevance)

Good Luck. Do your research on VBA ADODB recordsets and connections. Also, test your code on a DEV or TEST server to make sure you're getting the desired results.

Here's the code:

Expand|Select|Wrap|Line Numbers
  1. Public Sub cmdPROCESS_DATA()
  2.  
  3. Dim strDoM As String
  4. strDoM = Format(Date, "MM-DD-YY")
  5.  
  6.  
  7. ' Make connection to Remote DB
  8. Set conRemote = CurrentProject.Connection
  9. Set rstRemote = New ADODB.Recordset
  10.  
  11. ' Make connection to Local DB
  12. Set conLocal = CurrentProject.Connection
  13. Set rstLocal = New ADODB.Recordset
  14.  
  15.  
  16. strSQLSN = "SELECT dbo_AUB_RETROFIT_DATA.SERIAL_NUM"
  17.    strSQLSN = strSQLSN & " FROM dbo_AUB_RETROFIT_DATA"
  18.    strSQLSN = strSQLSN & " WHERE (((dbo_AUB_RETROFIT_DATA.SERIAL_NUM)=""" & strSN & """));"
  19.  
  20. rstRemote.Open "dbo_AUB_RETROFIT_DATA", conRemote, adOpenDynamic, adLockOptimistic
  21.    Set rstRemote = conRemote.Execute(strSQLSN)
  22.  
  23. lblStatus.Caption = "VALIDATING SERIAL NUMBER..."
  24.  
  25.  
  26. If Not rstRemote.EOF Then
  27.    rstRemote.MoveFirst
  28. End If
  29.  
  30. If Not rstRemote.EOF Then
  31.           Me.lblStatus.Caption = "SERIAL NUMBER REJECTED"
  32.           MsgBox "SERIAL NUMBER: " & strSN & " REJECTED" & vbCrLf & "NUMBER ALREADY IN USE", vbCritical, "SERIAL IN USE"
  33.           cmdRESET
  34.           Exit Sub
  35. End If
  36.  
  37. rstRemote.Close
  38.  
  39.  
  40. rstRemote.Open "dbo_AUB_RETROFIT_DATA", conRemote, adOpenDynamic, adLockOptimistic
  41. rstLocal.Open "tblTemp_Data", conLocal, adOpenDynamic, adLockOptimistic
  42. rstRemote.MoveFirst
  43. rstRemote.MoveLast
  44.  
  45.  
  46. If rstRemote.State = 0 Then
  47.                   'MsgBox "NO CONNECTION", vbCritical, "DB CONNECT"
  48.                   'End
  49.  
  50.               If rstLocal.State = 0 Then
  51.                    MsgBox "PROGRAM ERROR: NO DATABASE CONNECTED." & vbCrLf & "Close program and restart", vbCritical, "ERROR"
  52.                    cmdRESET
  53.                   End
  54.               End If
  55.  
  56.              With rstLocal
  57.                   .AddNew
  58.  
  59.                    .Fields(1).Value = strKit
  60.                    .Fields(2).Value = strMuffType
  61.                    .Fields(3).Value = strMuffNum
  62.                    .Fields(4).Value = strSN
  63.                    .Fields(5).Value = strCarbName
  64.                    .Fields(6).Value = strDoM
  65.  
  66.                   .Update
  67.              End With
  68.           Else
  69.  
  70.               'CHECK FOR CONNECTION TO LOCAL DB
  71.                If rstLocal.State = 0 Then
  72.                    MsgBox "PROGRAM ERROR: NO DATABASE." & vbCrLf & "Close program and restart", vbCritical, "ERROR"
  73.                   cmdRESET
  74.                   End
  75.                Else
  76.                   'Count records in "TEMP_DATA" to see if there are any records to upload
  77.                    If Not rstLocal.EOF Then
  78.                        rstLocal.MoveFirst
  79.                        LDB_COUNT = 0
  80.  
  81.                        Do Until rstLocal.EOF
  82.                            If rstLocal.EOF Then
  83.                                Exit Do
  84.                            End If
  85.  
  86.                            LDB_COUNT = LDB_COUNT + 1
  87.  
  88.                            If rstLocal.EOF Then
  89.                                Exit Do
  90.                            Else
  91.                                rstLocal.MoveNext
  92.                            End If
  93.                        Loop
  94.                    End If
  95.  
  96.  ' if LDB_COUNT is greater than 0 (zero) then we have data in temp table to upload.
  97.                If LDB_COUNT > 0 Then
  98.  
  99.                       'MOVE TO FIRST RECORD IN TEMP TABLE
  100.                    rstLocal.MoveFirst
  101.  
  102.                       'LOOP THROUGH DATA IN TEMP TABLE UNTIL ALL UOLOADED TO REMOTE DB
  103.                    Do Until rstLocal.EOF
  104.  
  105.                        With rstRemote
  106.                            .AddNew
  107.  
  108.                                .Fields(1).Value = strKit
  109.                                .Fields(2).Value = strMuffType
  110.                                .Fields(3).Value = strMuffNum
  111.                                .Fields(4).Value = strSN
  112.                                .Fields(5).Value = strCarbName
  113.                                .Fields(6).Value = strDoM
  114.  
  115.                           .Update
  116.                       End With
  117.  
  118.                       intLoopCNT = intLoopCNT + 1
  119.                       rstLocal.Delete
  120.                       rstLocal.Update
  121.                           'RS_LOCAL_DB.MoveNext
  122.                   Loop
  123.                   MsgBox "UPLOADED: " & intLoopCNT & " to remote DB", vbInformation, "INFO"
  124.               End If
  125.  
  126.                       'upload current data
  127.                   With rstRemote
  128.                       .AddNew
  129.  
  130.                                .Fields(1).Value = strKit
  131.                                .Fields(2).Value = strMuffType
  132.                                .Fields(3).Value = strMuffNum
  133.                                .Fields(4).Value = strSN
  134.                                .Fields(5).Value = strCarbName
  135.                                .Fields(6).Value = strDoM
  136.  
  137.                       .Update
  138.                   End With
  139.  
  140.  
  141.                   'Debug.Print "DB IS OPEN " & intDB_STATE
  142.           End If
  143.       End If
  144.       'CLOSE RST-------------------------------------------------
  145.   rstRemote.Close
  146.       'CLOSE RST-------------------------------------------------
  147.  rstLocal.Close
  148.  
  149.       ' Update LAST SN table with new serial number
  150. DoCmd.SetWarnings False
  151. DoCmd.RunSQL ("UPDATE tblLast_SN SET [LAST_" & strSNPrefix & "_SN] = '" & strSN & "' WHERE [LAST_" & strSNPrefix & "_SN] = '" & strTempSN & "';")
  152.  
  153. End Sub
  154.  
Mar 20 '09 #5
Thanks, DBrother, but this is a case of lasers in the hands of cavemen. I'm still progressing from Neanderthal to Cro Magnon.

I'll try to decipher your (very generous) advice, but I'm afraid it will all be far over my head. (Also, I'm using Access 2003; from a quick search of the web, I don't think that CurrentProject.Connection is available for that version.)

thanks again,


Dante
Mar 20 '09 #6
Yes CurrentProject.Connection is available for Access 2003. I use same method and version of Access, which is called ADO. ADO is Access's (newer versions) default data access method.

I realize you did a quick search and from your initial post, I could tell that you weren't very comfortable with the VBA syntax that is required to do what you want.

I also recommend the 'ACCESS 2003 VBA for dummies' (not saying that you are). This is a book that I picked up when I started a system's administrator position right out of college and it was very helpful and had a plethora of examples.

Some links for consideration:
http://www.vbexplorer.com/VBExplorer...er_ADO_DAO.asp

http://www.faculty.mcneese.edu/mpl/cs309/ADO/ado01.htm

http://support.microsoft.com/kb/184397

http://support.microsoft.com/kb/168336


Hope this helps.
Mar 20 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: D | last post by:
Hey guys- not sure where this post fits in, so I cc'd a few other groups as well- hope you dont mind... I have someone creating a database for me in Access 2000 (or is it called XP?). When it's...
4
by: BerkshireGuy | last post by:
Our IT department wants to place our Access 2000 tables on an SQL server due to the fact the tables are quite large. With that said, can we still use the Access queries or do we have to do...
5
by: DeanL | last post by:
Hi all, I'm having a few problems with a shared access 97 db. I have the database split with the tables on the server and everything else in "client" front ends with links to the tables, e.g....
5
by: B1ackwater | last post by:
We've fooled around with Access a bit, but only using the single-user store-bought version. It seems to be a good database - versatile and infinitely programmable - and can apparently be used as a...
5
by: Anns via AccessMonster.com | last post by:
My establishment has about 20 ms access db's that will be converted over (see subject). When we pull all the BE's over to SQL and the FE's on Sharepoint (.net) surely we don't have to change...
2
by: Steven | last post by:
A dump question: for project using access as front-end and RDBMS server (such as sqlsvr) as backend, do we create db in backend first before linking front-end with, or vice versa? Any comment...
5
by: Kip | last post by:
I have an office with approx 8 people. I have used Access with a Form on my personal PC for client records. I was wondering if I could put the Access table on a server and put shortcuts on each...
4
by: ThePhenix | last post by:
Hi everybody, I have recently been doing a conversion for my boss for a access 2000 database (both front and backend) to a MSSQL backend. I finished the conversion today (as quite a lot of the...
64
by: John | last post by:
Hello there, Im cursing my place of employment...and its taken me a month to realise it... The scenario: Ive just stepped into a role to migrate an access database to VB.Net. The access...
3
by: Earl Anderson | last post by:
One of the users in our departmental db has Read/Write permissions to a particular form. He was able to access and edit the form at will until 2 weeks ago. His current problem was that he was not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.