1

how to input the date and time to MS access by hitting a pushbutton at matlab figure?

enter image description here

my code for the date and time checkbox is:

m=1;
while m==1
m=get(hObject,'value');
txt=datestr(now);
set(handles.text7,'string',txt);
pause(1);
end

That code is located at a checkbox and date&time appears at static text. What I wanted to do is insert a pushbutton and whenever I will hit the pushbutton, It will be sent to the database table as an input but I don't know how to sync MS access to MatLab. Please help me because I'm very troubled right now :( Thank you in advance!

lloydknight
  • 57
  • 2
  • 14

2 Answers2

2

You can use the clipboard to establish a basic communication from Matlab to MS Access.

Matlab part - The button's callback function would populate the clipboard by the actual date and time. This is acheived with the code:

clipboard('copy', datestr(now));

Each time the button is pushed, the clipboard content will change.

MS Access part You can access the clipboard text content with the following

Dim MyData As DataObject
Dim strClip As String
Set MyData = New DataObject
MyData.GetFromClipboard
strClip = MyData.GetText

You can monitor the clipboard changes with a timer (see this SO for example).

You may alternatively populate a dedicated text file as the clipboard may be used by other processes or user actions.

Community
  • 1
  • 1
marsei
  • 7,691
  • 3
  • 32
  • 41
  • so where exactly will I put the code Dim MyData As DataObject Dim strClip As String Set MyData = New DataObject MyData.GetFromClipboard strClip = MyData.GetText I can't seem to find the clipboard in Access – lloydknight Sep 12 '13 at 12:17
  • This VBA code would be inserted in a macro that is related to your Access database. If you are not familiar with editing macros, you may create one, then convert it into VBA, then insert the VBA code above along with a monitoring loop. See the howto here (http://office.microsoft.com/en-gb/access-help/get-started-with-access-programming-HA001214213.aspx). – marsei Sep 12 '13 at 12:30
  • uhmm sorry for the late reply, I checked the link that you posted and It didn't indicate how to use VBA and the there's no procedure. Can you please state it in simpler way? I read the whole link and even copied the steps yet I can't seem to apply the code. Sorry for being a noob :( – lloydknight Sep 13 '13 at 05:34
  • You may try to look for some tutorial on the web - for example this on http://www.youtube.com/watch?v=G9pqmd2PSYk that shows you how to insert some VBA code on both form load and button click. – marsei Sep 13 '13 at 10:05
  • Ok I kind of sorted out on how to use the basic communication of MS Access and MatLab. The process is `MatLab-clipboard-MS Access`. What I really need is `MatLab-MS Access`. I need the direct exportation of data to MS Access using pushbuttons in MatLab. – lloydknight Sep 23 '13 at 20:11
2

I finally made the connection of matlab and ms access. Here's the tutorial on how to configure the connection first.

After successfully making a connection, I used this code on a callback.

conn = database('databasename','username','password');
dbpath = 'C:\Users\______.mdb'; %insert database path
tableName = 'datetime'; %insert tablename here in MSAccess
colname = {'column1'} %column of your tables in MsAccess
date = datestr(now); %the string of date and time
coldata = {date}
insert(conn,tableName,colname,coldata); %will insert the data to the database.
close(conn);
lloydknight
  • 57
  • 2
  • 14