|
-
Jan 21st, 2008, 01:13 PM
#1
Thread Starter
Lively Member
[RESOLVED] Access 2003 - Insert Record
Hi All,
I can trying to insert a record from a form using a button's onclick event but have run into some problems.
Problem 1:
When the onclick event is fired, I am prompted with an error message stating that the access database file can not be found in my documents. How do I over come that problem?
Problem 2:
It's not really a problem but more like a I have forgotten the syntax. When creating the insert syntax, I can't remember how to specify the textboxes as values. You can see from my code below.
Code:
Private Sub btnCreateEmp_Click()
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim sSQL As String
Dim strConString As String
Set cn = New ADODB.Connection
Set cmd = New ADODB.Command
strConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Client Details.MDB; Persist Security Info=False;Mode=Read|Write"
cn.ConnectionString = strConString
cn.Open
sSQL = "INSERT INTO EmployeeDetails ([FirstName]) VALUES ('Me!FNAME')"
With cmd
.ActiveConnection = cn
.CommandText = sSQL
.CommandType = adCmdUnknown
.Execute
End With
Set cmd = Nothing
cn.Close
Set cn = Nothing
End Sub
-
Jan 21st, 2008, 01:46 PM
#2
Re: Access 2003 - Insert Record
You didnt specify the complete path so it doesnt know where its located.
Data Source=Client Details.MDB;
Should be ...
Data Source=" & App.Path & "\Client Details.MDB;
If the database is in the same folder as the exe.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 21st, 2008, 04:15 PM
#3
Re: Access 2003 - Insert Record
For problem 2, see the article about it in the SQL section of our Database Development FAQs/Tutorials (at the top of the Database Development forum)
-
Jan 22nd, 2008, 09:08 AM
#4
Thread Starter
Lively Member
Re: Access 2003 - Insert Record
Thanks RobDog888 and si_the_geek for your replies. I can now insert records using a RecordSet but I am still having problems with the connection string.
Working Connection String:
Code:
conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ClientDetails.MDB; Persist Security Info=False;Mode=Read|Write"
Non-Working Connection String
Code:
conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\ClientDetails.MDB;Mode=Read|Write
When using the above connection string, a Run-Time error '424': Object Required is returned
-
Jan 22nd, 2008, 09:15 AM
#5
Re: Access 2003 - Insert Record
OK, well in that case I guess you aren't using Classic VB.
Are you doing this inside Access itself (thus VBA)?
-
Jan 22nd, 2008, 11:33 AM
#6
Re: Access 2003 - Insert Record
Sounds like it may be in Access but trying to connect to a secondary access database.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 22nd, 2008, 08:17 PM
#7
Thread Starter
Lively Member
Re: Access 2003 - Insert Record
Are you doing this inside Access itself (thus VBA)?
Everything is being written / designed within Access
-
Jan 22nd, 2008, 10:39 PM
#8
Re: Access 2003 - Insert Record
Thread Moved from the VB 6 Forum to the Office Dev. Forum
Ok since its not VB 6 the App.Path wont work as its not supported in VBA.
Are you trying to connect to a separate database or the same one the VBA code is in?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 23rd, 2008, 02:34 AM
#9
-
Jan 23rd, 2008, 03:35 AM
#10
Re: Access 2003 - Insert Record
Yes but if hes trying to connect to the same database then thats not needed as you can simply do a ...
Application.CurrentDb.Connection
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 23rd, 2008, 06:26 AM
#11
Thread Starter
Lively Member
Re: Access 2003 - Insert Record
 Originally Posted by RobDog888
Yes but if hes trying to connect to the same database then thats not needed as you can simply do a ...
Application.CurrentDb.Connection
The code is within the database. I now have it working using:
Code:
rs.Open stSQL, CurrentProject.Connection
Cheers to everyone that helped
-
Jan 23rd, 2008, 11:58 AM
#12
Re: [RESOLVED] Access 2003 - Insert Record
You should use the CurrentDb instead of the CurrentProject.
You can use the CurrentProject property to access the CurrentProject object and its related collections, properties, and methods.
The CurrentDb method returns an object variable of type Database that represents the database currently open in the Microsoft Access window.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|